2011-02-15 17 views
1

我想要做的就是能夠將返回的結果過濾爲特定的type_id。Zend_Search_Lucene,返回基於指定type_id的結果

首先我索引我想要搜索的所有文章。

SELECT 
     article_id, article_name, article_body, type_id 
    FROM 
     articles 
    WHERE 
     active = 1; 

$this->index = Zend_Search_Lucene::create($this->directory); 

    foreach ($result as $key => $value) 
    { 
     $this->doc = new Zend_Search_Lucene_Document(); 
     //Indexed 
     $this->doc->addField(Zend_Search_Lucene_Field::Text('article_name',$value['article_name'])); 
     $this->doc->addField(Zend_Search_Lucene_Field::Text('article_body', $value['article_body'])); 
     //Indexed 

     //Unindexd 
     $this->doc->addField(Zend_Search_Lucene_Field::UnIndexed('article_id', $value['article_id'])); 
     $this->doc->addField(Zend_Search_Lucene_Field::UnIndexed('type_id', $value['type_id'])); 
     //Unindexd 

     $this->index->addDocument($this->doc); 
    } 

    $this->index->commit(); 
    $this->index->optimize(); 

現在,當我執行搜索時,如果我想,以濾除TYPE_ID的結果,我會怎麼做它使用 - Zend公司的>查找()命令?

$this->index = Zend_Search_Lucene::open($this->directory); 

//Based on the type_id, I only want the indexed articles that match the type_id to be returned. 
$results = $this->index->find('+type_id:2 '.$search_term.'*'); 

//Cycle through the results. 

我想zend的檢索用Lucene來基於我指定的唯一TYPE_ID返回結果。

+0

如何使用AND運算符?例如'+ type_id:2 AND'。$ search_term。'*' – Marcin 2011-02-15 11:36:57

回答

0

您無法搜索未索引的術語(如type_id)。如果您希望字段可搜索,但沒有標記化,想要將其添加爲關鍵字:

$this->doc->addField(Zend_Search_Lucene_Field::Keyword('type_id', $value['type_id'])); 

manual

索引字段是不可搜索, 但它們與返回搜索 命中。數據庫時間戳,主要的 密鑰,文件系統路徑和其他 外部標識符是很好的 UnIndexed字段的候選人。