As the observation system can be
used for many observers, it is possible that some models may be sending out notifications that are not relevant
to the SearchIndexer. To test for this we see if the model implements the function getSearchIndexFields() (#1).
If it does, then we call the function (#2) to retrieve the data from the model in format that is suitable for our
search index and then we create the document ready to be added to the index (#3).
Listing 8.7: SearchIndexer::_addToIndex() add to the search index
class SearchIndexer
{
// ...
protected static function _addToIndex($doc)
{
$dir = self::$_indexDirectory; 1
$index = Zend_Search_Lucene::open($dir); |1
$index->addDocument($doc); 2
$index->commit(); |2
}
1 Open the search index
3. Add the document and store
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Adding the document to the index is really easy. All we need to do is open the index using the directory
that was set up in the bootstrap(#1) and then add the document (#2). Note that we need to commit the index to
ensure that it is saved for searching on. This isn??™t needed if you add lots of documents as there is an automatic
commit system that will sort it out for you.
Pages:
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234