问题
I have one field and multiple values for it and I am trying to build a simple query which should look like this
field:(value1 value2 value3)
I have a map with fields and values and I am doing something like this
fieldsMap
"field1" -> "[data1]"
"field2" -> "[value1,value2,value3]"
Code to build lucene query:
fieldsMap
.entrySet()
.forEach(field -> {
try {
QueryParser queryParser = new ComplexPhraseQueryParser(field.getKey(), new StandardAnalyzer());
booleanQueryBuilder.add(queryParser.parse(QueryParser.escape(field.getValue())), BooleanClause.Occur.MUST);
} catch (ParseException e) {
e.printStackTrace();
}
});
Generated output:
+field1:data1 +(field2:val1 field2:val2 field2:val3)
But how can I generate something like this
+field1:data1 +field2:(value1 value2 value3)
回答1:
You already did. +field1:data1 +(field2:val1 field2:val2 field2:val3)
is equivalent to +field1:data1 +field2:(val1 val2 val3)
来源:https://stackoverflow.com/questions/55841110/build-lucene-query-for-multi-values-in-one-field