我想要做的是能够将返回的结果过滤到特定的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的结果。
答案 0 :(得分:0)
您无法搜索未编入索引的字词(例如type_id)。如果您希望字段可搜索,但未标记,则需要将其添加为关键字:
$this->doc->addField(Zend_Search_Lucene_Field::Keyword('type_id', $value['type_id']));
来自manual:
UnIndexed字段无法搜索, 但他们会通过搜索返回 命中。数据库时间戳,主要 密钥,文件系统路径等 外部标识符很好 UnIndexed字段的候选人。