如何将Solr中的两个查询与ComplexPhraseQueryParser结合使用?

时间:2017-01-03 05:14:09

标签: search solr lucene

  1. 当我在Solr 4.0中分别使用以下两个过滤器查询进行搜索时,它会按预期工作。

    {!complexphrase inOrder=true}employeeName_t:"Mike R*"

    empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z]

  2. 但是当我合并这两个查询时(无论顺序如何),我没有得到正确的搜索结果。

    • {!complexphrase inOrder=true}employeeName_t:"Mike R*" AND empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z]

    此查询在Solr中为我提供零搜索结果

    “回复”:{ “numFound”:0, “开始”:0, “maxScore”:0, “文档”:[] }

    • empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z] AND {!complexphrase inOrder=true}employeeName_t:"Mike R*"

    而查询顺序的更改会给我解析异常,如下所示

    “错误”:{ “msg”:“org.apache.solr.search.SyntaxError:org.apache.lucene.queryparser.classic.ParseException:不能 解析'employeeName_t:\“Mike':第1行第21栏的词汇错误。遇到:之后:\”\\“Mike \”“,代码:400 }

    使用 ComplexPhraseQueryParser 在solr中进行部分搜索。需要同时使用这两个查询。非常感谢任何建议。

1 个答案:

答案 0 :(得分:0)

我建议你使用fq参数。

使用查询检索文档:" Mike R *"并使用fq参数中指定的日期进行过滤。

示例:

q={!complexphrase inOrder=true}employeeName_t:"Mike R*"&fq=empDate_dt:["2016-10-10T00:00:00Z" TO "2016-10-10T23:59:59Z"]