Therefore we need to override the open() and create() function too as shown in
listing 8.9.
Listing 8.8: Overriding open() so that it all works
class Places_Search_Lucene extends Zend_Search_Lucene
{
public static function create($directory)
{
return new Zend_Search_Lucene_Proxy(
new Places_Search_Lucene($directory, true)); A
}
public static function open($directory)
{
return new Zend_Search_Lucene_Proxy(
new Places_Search_Lucene($directory, false));
}
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
// continue class...
A instantiate an instance of Places_Search_Lucene
The create() and open() functions in Listing 8.8 are very simple but also very necessary and now
everything works as expected once we have updated SearchIndexer::_addToIndex() to reference
Places_Search_Lucene. This is shown in Listing 8.9.
Listing 8.9: Correcting SearchIndexer::_addToIndex()
protected static function _addToIndex($doc)
{
$dir = self::$_indexDirectory;
$index = Places_Search_Lucene::open($dir); 1
$index->addDocument($doc); 2
$index->commit();
}
1 open the index using Places_Search_Lucene
2. add the document removing duplicates
The function in listing 8.
Pages:
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236