0

I have a CMS that I am adding Site Search functionality. The application uses the full Zend Framework MVC stack.

At this point if seems that I should be creating/using a Search model. All models I've created up to this point have been based on database tables. What would a Search model look like? Am I taking the wrong approach?

Sonny
  • 8,204
  • 7
  • 63
  • 134

1 Answers1

1

Basically by using Zend_Search_Lucne you will create an index of your database on to your web-server . Hence shifting load from database server to web-server (which is good thing since you can easily have many webserver but not many database server).

To build index . You treat each row of your table which you want to be searchable as a single Zend_Search_Lucene_Document in lucene . And columns becames Zend_Search_Lucene_Field . You add these documents into your index which lives on hardisk . At the time of searching you query against this index .

To know more http://framework.zend.com/manual/en/zend.search.lucene.index-creation.html

Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • I understand that part of it. What I am trying to wrap my head around is where I put that code. – Sonny Oct 11 '11 at 17:41
  • Code will be divided in two parts one shd go inside controller of admin module to build index (you might want to run it as cron job ) and second part which will be used to query against index should be in any controller of frontend. – Mr Coder Oct 11 '11 at 17:46
  • I was planning on updating the index as content is edited, is that not a good idea? – Sonny Oct 11 '11 at 18:16
  • "Lucene index file format doesn't support document updating. Documents should be removed and re-added to the index to effectively update them." Its quality of result vs performance . I rather choose performance . – Mr Coder Oct 12 '11 at 03:04
  • No I don't think that it's a good idea to update the index as it is edited. Unlike sphinxsearch, lucene does not have delta indexes which means rebuilding your indexes might take some time. – Mark Basmayor Oct 12 '11 at 03:36
  • @Open Source Lover - I know that I would have to delete the document and then add it back when a change is made to the content. – Sonny Oct 12 '11 at 13:25
  • @Mark Basmayor - After deleting and adding a document back, I would have to rebuild the index, and you're saying it's a resource intensive operation? – Sonny Oct 12 '11 at 13:26