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返回結果。
如何使用AND運算符?例如'+ type_id:2 AND'。$ search_term。'*' – Marcin 2011-02-15 11:36:57