PHP Zend Lucene 具有多个条件的搜索查询失败

发布于 2024-12-12 07:57:02 字数 807 浏览 0 评论 0原文

Zend Lucene 搜索文档

Lucene Document
    pk:Keyword
    category_id:Keyword
    title:UnStored
    description:UnStored

这是我的字符串查询“java lucene AND +category_id:7”。 结果如下:

Array
(
    [0] => Array
        (
            [pk] => 209
            [category_id] => 7
            [id] => 0
            [score] => 0.40750848701418
        )
   [1] => Array
        (
            [pk] => 225
            [category_id] => 7
            [id] => 3
            [score] => 0.30750848701619
        )

    [2] => Array
        (
            [pk] => 211
            [category_id] => 8 ====>>> WRONG!!! 
            [id] => 2
            [score] => 0.37152213415004
        )

)

您可以仅对category_id = 7 进行查询搜索吗? 提前致谢。

Zend Lucene Search Document

Lucene Document
    pk:Keyword
    category_id:Keyword
    title:UnStored
    description:UnStored

This is my string query "java lucene AND +category_id:7".
Result here:

Array
(
    [0] => Array
        (
            [pk] => 209
            [category_id] => 7
            [id] => 0
            [score] => 0.40750848701418
        )
   [1] => Array
        (
            [pk] => 225
            [category_id] => 7
            [id] => 3
            [score] => 0.30750848701619
        )

    [2] => Array
        (
            [pk] => 211
            [category_id] => 8 ====>>> WRONG!!! 
            [id] => 2
            [score] => 0.37152213415004
        )

)

Can you do a Query search on the category_id = 7 only??
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2024-12-19 07:57:02

我已经通过使用 Zend 查询解析结果解决了这个问题,

$strQuery = Zend_Search_Lucene_Search_QueryParser::parse('java lucene');

$cateTerm  = new Zend_Search_Lucene_Index_Term(7 , 'category_id');
$cateQuery = new Zend_Search_Lucene_Search_Query_Term($cateTerm);

$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->addSubquery($strQuery, true /* required */);
$query->addSubquery($cateQuery, true /* required */);

结果将仅在category_id = 7中:)

I had solved this problem by using Zend Query Parsing

$strQuery = Zend_Search_Lucene_Search_QueryParser::parse('java lucene');

$cateTerm  = new Zend_Search_Lucene_Index_Term(7 , 'category_id');
$cateQuery = new Zend_Search_Lucene_Search_Query_Term($cateTerm);

$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->addSubquery($strQuery, true /* required */);
$query->addSubquery($cateQuery, true /* required */);

Results will be only in category_id = 7 :)

最舍不得你 2024-12-19 07:57:02

您可以从查询中删除 AND +category_id:7 ,您想要的是一个过滤器,因为不需要 +category_id:7 作为排名值。

我不知道如何用 Zend_Lucene 实现它,但在 solr 中我曾经传递 fq 参数,这可能会给你一个提示:)

过滤是一个限制搜索空间并只允许子集的过程考虑搜索命中的文档。您可以使用此功能来实现搜索结果中的搜索。 Lucene自带各种内置过滤器如BooleanFilter、CachingWrapperFilter、ChainedFilter、DuplicateFilter、PrefixFilter、QueryWrapperFilter、RangeFilter、RemoteCachingWrapperFilter、SpanFilter等(THE NATIVE JAVA VERSION)过滤器可以传递给IndexSearcher的搜索方法来过滤符合过滤条件的文档。

You can remove the AND +category_id:7 from you query, what you want is a filter since +category_id:7 is not needed as a ranked value.

I don't know how to implement it with Zend_Lucene but in solr I used to pass fq parameter, this may give you a hint :)

Filtering is a process that constrains the search space and allows only a subset of documents to be considered for search hits. You can use this feature to implement search-within-search results. Lucene comes with various built-in filters such as BooleanFilter, CachingWrapperFilter, ChainedFilter, DuplicateFilter, PrefixFilter, QueryWrapperFilter, RangeFilter, RemoteCachingWrapperFilter, SpanFilter, etc.(THE NATIVE JAVA VERSION) Filter can be passed to IndexSearcher's search method to filter documents that match the filter criteria.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文