Zend_Search_Lucene索引更新

蒋奇
2023-12-01

更新一个索引

 

  1. //更新多一个索引  
  2.            $index = new Zend_Search_Lucene(INDEX_DATA);  
  3.            Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());  
  4.            $doc = new Zend_Search_Lucene_Document();  
  5.            $doc ->addField(Zend_Search_Lucene_Field::unStored('key',md5($rid),'utf-8'));  
  6.            $doc ->addField(Zend_Search_Lucene_Field::text('logTitle',$data['logTitle'],'utf-8'));  
  7.            $doc ->addField(Zend_Search_Lucene_Field::text('logContent',$data['logContent'],'utf-8'));  
  8.            $index->addDocument($doc);  
  9.            $index ->optimize();  
  10.            $index->commit();  

//更新多一个索引 $index = new Zend_Search_Lucene(INDEX_DATA); Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); $doc = new Zend_Search_Lucene_Document(); $doc ->addField(Zend_Search_Lucene_Field::unStored('key',md5($rid),'utf-8')); $doc ->addField(Zend_Search_Lucene_Field::text('logTitle',$data['logTitle'],'utf-8')); $doc ->addField(Zend_Search_Lucene_Field::text('logContent',$data['logContent'],'utf-8')); $index->addDocument($doc); $index ->optimize(); $index->commit();

 

删除索引

 

  1. //删除索引  
  2.         $index = new Zend_Search_Lucene(INDEX_DATA);  
  3.         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');//设置查询器编码,搜索中文必须!  
  4.         $hits = $index ->find(md5($id));  
  5.         foreach ($hits as $hit){  
  6.             $index->delete($hit->id);  
  7.         }  
  8.         $index -> commit();  

//删除索引 $index = new Zend_Search_Lucene(INDEX_DATA); Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');//设置查询器编码,搜索中文必须! $hits = $index ->find(md5($id)); foreach ($hits as $hit){ $index->delete($hit->id); } $index -> commit();

 

修改索引

 

  1. //更新修改索引  
  2.             $index = new Zend_Search_Lucene(INDEX_DATA);  
  3.             Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());  
  4.             Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');//设置查询器编码,搜索中文必须!  
  5.             $hits = $index ->find(md5($id));  
  6.             foreach ($hits as $hit){  
  7.                 $index->delete($hit->id);  
  8.             }  
  9.             $doc = new Zend_Search_Lucene_Document();  
  10.             $doc ->addField(Zend_Search_Lucene_Field::unStored('key',md5($id),'utf-8'));  
  11.             $doc ->addField(Zend_Search_Lucene_Field::text('logTitle',$data['logTitle'],'utf-8'));  
  12.             $doc->addField(Zend_Search_Lucene_Field::text('logContent',$data['logContent'],'utf-8'));  
  13.             $index->addDocument($doc);  
  14.             $index->optimize();  
  15.             $index -> commit();  

转载于:https://www.cnblogs.com/wangbin/archive/2010/09/20/1831713.html

 类似资料: