9 is the same as that in listing 8.7, with the exception of calling
Places_Search_Lucene::open() (#1). This means that the call to addDocument() (#2) now calls our newly
written function so that we can be sure that there are no duplicate pages in the search index. We now have a
working system for adding updated content to our search index. We now need to implement the search system
on the front end do that our users can find what they are looking for.
Re-indexing the entire site
Now we have the ability to update the index as new content is added, we can utilize all the code we have
written to easily enable re-indexing all the data in the site. This is useful for supporting bulk inserting of data
and also as a recovery strategy if the index is damaged or accidentally deleted. The easiest way to support reindexing
is to create a controller action, search/reindex which is shown in listing 8.10.
Listing 8.9: The re-indexing controller
public function reindexAction()
{
$index = Places_Search_Lucene::create( A
SearchIndexer::getIndexDirectory());
$places = new Places(); B
$allPlaces = $places->fetchAll();
foreach($allPlaces as $place) { C
$doc = SearchIndexer::getDocument($place); C
$index->addDocument($doc); C
}
}
A Create a new index, wiping the old one
B Only the Places model has data to index
C Add each document in turn
The reindex action is very simple and uses Zend_Search_Lucene??™s create() function to start a
new index, effectively overwriting any current index.
Pages:
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237