问题描述
继我之前的问题:
我遇到了一个问题,我想将解析后的 Query
( Query.toString()
)发送到 QueryParser
使用SOLR且默认操作符为 AND
的Web服务.因为Lucene将 OR
作为其默认运算符,所以所有或"的术语都保持原样".例如.给定查询:
I've run into a problem where I'm wanting to send a QueryParser
parsed Query
(Query.toString()
) onto a webservice that uses SOLR with a default operator of AND
. Because Lucene has OR
as its default operator any OR'ed terms are left "as is". E.g. given the query:
(f1:cat OR f1:dog) AND f2:cow AND f3:"tree frog"
一旦解析(使用 QuerParser.setDefaultOperator(QueryParser.Operator.AND)
),字符串版本将变为:
once parsed (with QuerParser.setDefaultOperator(QueryParser.Operator.AND)
), the String version becomes:
+(f1:cat f1:dog) +f2:cow +f3:"tree frog"
当使用假定的 AND
运算符将其传递给SOLR时,两个f1项将得到AND'ed而不是OR'ed.
When this is passed to SOLR, with an assumed AND
operator, the two f1 terms get AND'ed instead of OR'ed.
我能想到的唯一解决方法是将SOLR安装更改为使用OR作为其默认布尔运算符...还有其他建议吗?
The only work-around I can think of is to change my SOLR installation to use OR as its default Boolean operator... Any other suggestions?
推荐答案
可以根据每个请求覆盖默认运算符.例如:
The default operator can be overriden on a per-request basis. For exemple :
使用参数: http://solr/select?q = query& q.op = OR
或使用局部参数: http://solr/select?q = {!lucene q.op = OR} query
有关更多详细信息,请参见 SolrQuerySyntax .
See SolrQuerySyntax for more details.
这篇关于Lucene QueryParser-产生一个“便携式"的查询以发送到SOLR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!