2

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

  • in bootstrap, tried using `$lucene = new Zend_Search_Lucene(APPLICATION_PATH . '/lucene', true);` instead of ::create, and then adding `$lucene = new Zend_Search_Lucene(APPLICATION_PATH . '/lucene'); # ::open` , and then using Zend_Registry `Zend_Registry::set('lucene', $lucene);` and calling the registered object in test1() and test2(). No change in result.. – Nomen Nescio Nov 23 '11 at 08:43

1 Answers1

0

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 :)

  • sorry, incorrect answer. but this one is: try putting this one in bootstrap instead `try { $lucene = Zend_Search_Lucene::open(APPLICATION_PATH . '/lucene'); } catch (Zend_Search_Lucene_Exception $e) { $lucene = Zend_Search_Lucene::create(APPLICATION_PATH . '/lucene'); } $lucene->setDefaultSearchField('userName');` – Nomen Nescio Nov 24 '11 at 08:59