首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zend_Search_Lucene,根据指定的type_id返回结果

Zend_Search_Lucene,根据指定的type_id返回结果
EN

Stack Overflow用户
提问于 2011-02-15 18:22:02
回答 1查看 205关注 0票数 1

我想要做的是能够将返回的结果过滤到特定的type_id。

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

代码语言:javascript
复制
    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()命令来实现呢?

代码语言:javascript
复制
$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的结果。

EN

回答 1

Stack Overflow用户

发布于 2011-03-30 18:26:52

您不能搜索未编制索引的术语(如type_id)。如果您希望该字段是可搜索的,但不是标记化的,则需要将其添加为关键字:

代码语言:javascript
复制
$this->doc->addField(Zend_Search_Lucene_Field::Keyword('type_id', $value['type_id']));

manual中:

UnIndexed字段不可搜索,但会随搜索结果一起返回。数据库时间戳、主键、文件系统路径和其他外部标识符都是UnIndexed字段的理想候选者。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5002411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档