【问题标题】:Combine a range query with a multi-term query in Zend Lucene在 Zend Lucene 中将范围查询与多项查询相结合
【发布时间】:2011-11-05 11:27:45
【问题描述】:

我正在使用 Zend Lucene,想知道是否可以将范围查询与多项查询结合起来执行单个搜索操作。

例如,您构造一个范围查询,如下所示:

$from = new Zend_Search_Lucene_Index_Term('20020101', 'mod_date');
$range = new Zend_Search_Lucene_Search_Query_Range(
             $from, null, true // inclusive
         );

然后像这样构造一个多词查询:

//this example uses only 1 term but the real use case has many terms forming the multiterm
$multi_term = Zend_Search_Lucene_Search_Query_MultiTerm(new Zend_Search_Lucene_Index_Term('foo','title'));

然后不知何故,

$combined = combine($range,$multi_term);
$hits  = $index->find($combined);

使用 Zend Lucene 可以实现类似的功能吗?

【问题讨论】:

    标签: php zend-framework lucene


    【解决方案1】:

    使用布尔查询。

    $query = new Zend_Search_Lucene_Search_Query_Boolean();
    $rangeQuery = ...
    $multiTermQuery = ...
    $query->addSubquery($rangeQuery, true)
    $query->addSubquery($multiTermQuery, true)
    

    【讨论】:

      【解决方案2】:

      一种不那么程序化但同样有效的方式(这与当前的ZendSearch 相关)是动态构建查询字符串而不是在代码中。

      例如:

      +mod_date:[20020101 TO 20030101] +foo:bar

      将它传递给query 函数并允许它。从我的角度来看,问题是同一查询中的模糊查询和关键字。在代码中这是不可能的,但可以使用查询字符串来完成。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多