我想要做的是能够将返回的结果过滤为特定的 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 的 ->find() 命令来实现呢?
$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-search-lucene 仅根据我指定的 type_id 返回结果。