问题描述
我有一个查询 -license:CC-BY-NC"AND -license:"CC-BY-ND 4.0(Int)"
像这样传递到PrecedenceQueryParser.parse:
I have a query -license:"CC-BY-NC" AND -license:"CC-BY-ND 4.0 (Int)"
to be passed into PrecedenceQueryParser.parse like this:
Query query = new PrecedenceQueryParser().parse(filter, '')
但是在生成的查询中,您可以看到,子句类似于 -lincense:CC-BY-NC
,"迷路了.
But in the generated query you can see, clauses are like -lincense:CC-BY-NC
, "" are lost.
是否有任何设置可以保留"?
Is there any settings to keep the ""?
=====================更新===========================
===================== UPDATE ===========================
我了解,由于我正在寻找CC-BY-ND 4.0(Int)的匹配项,不带双引号(双引号仅用于使其成为短语).这就是为什么query.clauses [1] .query没有"的原因.围绕CC-BY-ND 4.0(Int)
I understand that since I'm looking for a match of CC-BY-ND 4.0 (Int),without double quotes (double quotes are just used to make it a phrase). That's why query.clauses[1].query doesn't have "" around the CC-BY-ND 4.0 (Int)
现在我这样做:
def bqb = new BooleanQuery.Builder()
clauses.each { clause ->
bqb.add(clause.query, clause.prohibited ? BooleanClause.Occur.SHOULD : BooleanClause.Occur.MUST_NOT)
}
String s = bqb.build().toString()
构建一个BooleanQuery并将子句放在一起,
build a BooleanQuery and put clauses together,
s等于 license:CC-BY-ND 4.0(Int)许可证:CC-BY-NC
这绝对不是我想要的,我需要CC-BY-ND 4.0(Int)用双引号引起来.有什么办法吗?
This is definitely not what I want, I need CC-BY-ND 4.0 (Int) to be surrounded by double-quotes. Is there any way to do that?
Gibbs可能是一个解决方案,但我认为有些棘手.
Gibbs's could be a solution but a bit tricky I think.
推荐答案
您需要对它们进行转义.
You need to escape them.
当您通过 -license时:"CC-BY-NC"AND -license:"CC-BY-ND 4.0(Int)"
,请使用以下
-license:"\"CC-BY-NC\"" AND -license:"\"CC-BY-ND 4.0 (Int)\""
这篇关于Lucene QueryParse丢弃“解析时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!