Zend_Search_Lucene count() failed after addDocument() in another place
-
07-03-2021 - |
Question
in my bootstrap:
protected function _initLucene()
{ Zend_Search_Lucene::create(APPLICATION_PATH . '/lucene')->setDefaultSearchField('userName'); }
in my data mapper:
public function test1() {
$lucene = Zend_Search_Lucene::open(APPLICATION_PATH . '/lucene');
$document = new Zend_Search_Lucene_Document();
$document->addField(Zend_Search_Lucene_Field::Text('userName', 'someValue'));
$lucene->addDocument($document);
$lucene->commit();
return $lucene->count(); # returns 1, correct
}
public function test2() {
$lucene = Zend_Search_Lucene::open(APPLICATION_PATH . '/lucene');
return $lucene->count(); # returns 0, incorrect!!
}
in my indexController:
public function indexAction() {
echo $myMapper->test1() # prints 1
}
public function testAction() {
echo $myMapper->test2() # prints 0 ??
}
As info, i am using windows/ntfs/xampp and zf 1.11.11. So when i direct my browser first to /index/index, lucene correctly prints 1, but when i continue directing to /index/test, lucene incorrectly prints 0. Is it not possible to put addDocument() and find() in separate places/functions, as i am planning to put find() in testAction and test2?
please help me to identify the problem
p.s. i have tried the following:
- turning $myMapper to static
- moving the code from mapper to controller
both does no difference
Solution
Found the problem!!
Can't init lucene / ::create at bootstrap, so you have to init / ::create somewhere else. In my case, i used init() of indexController :)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow