与Zend Lucene和相关模型的Symfony(带有外键) [英] Symfony with Zend Lucene and related models (with foreign keys)

查看:87
本文介绍了与Zend Lucene和相关模型的Symfony(带有外键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我意识到Zend Lucene实现的主要缺点时,我正在使用Symfony 1.4和Doctrine开发应用程序.

Well I was developing an application usin Symfony 1.4 and Doctrine when I realized a major drawback on my Zend Lucene implementation.

我有一个称为Publication的模型,该模型(通过外键关系)与其他一些模型(主题,体裁,语言,作者等)相关联,并且在将新文档添加到其中时得到它们的名字.索引(使用Jobeet教程方法),以便我可以搜索具有给定主题,体裁,语言,作者等的出版物.问题是如果由于某种原因我决定更改那些相关模型之一的名称Zend Lucene索引将不会更新.

I have a model called Publication that is related (via foreign key relations) with a few other models (subjects, genres, languages, authors, etc.) and I'm getting they're names when adding a new document to the index (using the Jobeet tutorial way) so that I can search for publications with a given subject, genre, language, author, etc... The problem is if for some reason I decide to alter the name of one of those related models the Zend Lucene index will not get updated.

我只能提出的两种解决方案是:

The only two solutions I could come up with were:

  1. 定期对所有出版物重新编制索引,以确保对相关模型所做的任何更改都可以在索引上进行更新(但是此解决方案不允许实时更新索引)

  1. Re-index all the publications regularly to guarantee that any changes made to the related models gets updated on the index (however this solution doesn't allow the index to be updated in real time)

获取与给定模型相关的所有出版物,并在它们更新后重新编制索引(使用save(),postSave(),postUpdate()或Doctrine上可以提供的任何东西) . ->这个解决方案似乎很棒...它只会为链接到更新模型的出版物重建索引吗?好吧,如果您链​​接了几千(1000)个出版物,那么将需要几分钟的时间进行更新(是的,我已经对其进行了测试),并且在用户表单上,它将超时,因为它需要30秒钟以上的时间(即使不这样做).如果让用户在屏幕上等待几分钟以等待页面加载完成,那就太糟糕了.

Get all the publications that are related with a given model and re-index them after it gets updated (using the save(), postSave(), postUpdate() or whatever you can come up with on Doctrine). --> This solution seemed great... It will only rebuild the index for the publications that are linked to the updated model right? Well, if you have something like a thousand (1000) publications linked to it will take a few minutes to update (yeah I tested it) and on a user form it will timeout because it takes over 30 seconds (and even if it don't it would be bad to have a user looking at the screen for a few minutes awaiting for the page to finish to load).

所以我想知道是否还有其他解决方案?有没有一种方法可以根据相关模型的更改动态地更新索引,而无需挂整个Pahe?也许将任务放在后台运行?有这种方法吗?

So what I want to know is if there's another solution? Is there a way to update an index on the fly based on a change on a related model without hanging the whole pahe? Maybe putting the task to run on the background or something? Is there such a way?

如果Lucene无法做到这一点,那么有没有办法使用MySQL(带有InnoDB表)进行全文搜索,而又没有使用Zend Lucene这样的缺点呢?如果有这样的工具,我会很乐意重构代码以容纳其他库.

If there's no way to do this with Lucene is there any way to use Full-Text Search with MySQL (with InnoDB tables) without using Zend Lucene that doesn't have such a drawback? If there's such a tool I'd glady refactor my code to accommodate a different library.

您能帮我吗?预先感谢!

Could you please help me with this? Thanks in advance!

推荐答案

嗯...我在回答自己.考虑了一段时间之后,我以一个妥协的解决方案告终.

Well... I'm answering my self. After thinking about it for some time I ended with a compromisse solution.

在我的模型上,我已经与一个表一对一的关系,该表仅用于存储有关发布的元信息,因此我最终插入了一个称为reindex的新列(即布尔值").这样,每次我更新与出版物相关的实体(在生产中很少会发生,但我想为此做好准备)时,它将把与该出版物相关的每个出版物标记为需要重新编制索引.比起我有一个可以在cron作业或Task Scheduler上运行的任务,该任务将仅对标记为需要它的发布重新编制索引.这样,我可以将此任务设置为每周晚几次运行几次,以保持索引的一致性.

On my model I already have a one-to-one relationship with a table that is used only for storing meta-information about a publication so I ended up inserting a new column called reindex (that is a "boolean"). This way everytime I update an entity related with a publication (something that in production will happen very seldom but I want to be prepared for it) it will mark every publication that is related to it as needing reindexing. Than I have a task that can be run on cron job or Task Scheduler that will only reindex the publications that are marked as needing it. This way I can set this task to run a few times a week at late hours to keep the Index consistent.

这不是一个完美的解决方案,但是这是我仅使用PHP和Zend Lucene就能想到的最好的解决方案.

It's not a perfect solution but is the best I can came up with using only PHP and Zend Lucene.

这篇关于与Zend Lucene和相关模型的Symfony(带有外键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆