我想要做的是能够将返回的结果过滤到特定的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的结果。
发布于 2011-03-30 18:26:52
您不能搜索未编制索引的术语(如type_id)。如果您希望该字段是可搜索的,但不是标记化的,则需要将其添加为关键字:
$this->doc->addField(Zend_Search_Lucene_Field::Keyword('type_id', $value['type_id']));在manual中:
UnIndexed字段不可搜索,但会随搜索结果一起返回。数据库时间戳、主键、文件系统路径和其他外部标识符都是UnIndexed字段的理想候选者。
https://stackoverflow.com/questions/5002411
复制相似问题