This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » plugins » Search plugins » Error in updating the details in zend lucene in symfony
Error in updating the details in zend lucene in symfony [message #79019] Wed, 27 May 2009 07:50
senthilkumar26  is currently offline senthilkumar26
Messages: 3
Registered: May 2009
Location: Bangalore
Junior Member
Hello,

I have implemented zend search lucene in symfony like the below code
$zendSearchLucenePath = $siteRootDir . sfConfig::get('app_search_user_index_file');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
if (!is_dir($zendSearchLucenePath)) {
	$index = new Zend_Search_Lucene($zendSearchLucenePath, true);
} else {
	$index = new Zend_Search_Lucene($zendSearchLucenePath);
}
		
// First find any reference to this user and delete them
$users = $index->find('user_id:'.$this->getId());
foreach($users as $user) {
	$index->delete($user->user_id);
}
// Create New Zend Search Lucene Document
$doc = $this->generateZSLDocument();
$index->addDocument($doc);
$index->commit;

public function generateZSLDocument() {		
      $doc = new Zend_Search_Lucene_Document();
      $doc->addField(Zend_Search_Lucene_Field::Keyword('user_id', $this->getId()));
      $doc->addField(Zend_Search_Lucene_Field::Keyword('username', $this->getUsername()));
      $doc->addField(Zend_Search_Lucene_Field::Keyword('email', $this->getEmail()));
      $doc->addField(Zend_Search_Lucene_Field::Text('firstname', $this->getFirstname()));
      $doc->addField(Zend_Search_Lucene_Field::Text('lastname', $this->getLastname()));
      $doc->addField(Zend_Search_Lucene_Field::Text('location', $this->getLocation()));
      $doc->addField(Zend_search_Lucene_Field::Unstored('contents', "{$this->getEmail()} {$this->getFirstname()} {$this->getLastname()} {$this->getUsername()} {$this->getLocation()}"));

      // return the document
      return $doc;
}


After inserting the first record, i am try to updating it but i am getting the error in this line
$index->delete($user->user_id);

This error is because in Lucene.php, there are checking like this
if ($id >= $this->_docCount) {
    require_once 'Zend/Search/Lucene/Exception.php';
    throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
}


So, i above condition we can't able to delete the last record right?

After Updating the record, i am searching the word like the below code
$zendSearchLucenePath = $siteRootDir . sfConfig::get('app_search_user_index_file');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
$index = new Zend_Search_Lucene($zendSearchLucenePath);
	
$hits = $index->find(strtolower($query));
foreach($hits as $hit) {
    echo $hit->user_id.' -- '.$hit->username.' -- '.$hit->email.' -- '.$hit->firstname.' -- '.$hit->lastname.'<br />';
}


If i am updating the record for 3 times, while searching i am getting all 3 records like this

2 -- Kumar_260783 -- vel.kumar@gmail.com -- Kumar -- Vel
2 -- Kumar_2607 -- vel.kumar@gmail.com -- Kumar -- Vel
2 -- Kumar_26 -- vel.kumar@gmail.com -- Kumar -- Vel


Please can anyone help me, how to handle this type of errors.

Thanks & Regards,
Senthil R
Previous Topic:Which search plugin to use to implement site-wide search?
Next Topic:Plugin similar to script catalogue
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software