I have implemented zend search lucene in symfony like the below code
- Code: Select all
$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
- Code: Select all
$index->delete($user->user_id);
This error is because in Lucene.php, there are checking like this
- Code: Select all
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
- Code: Select all
$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
- Code: Select all
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
