Build Lucene Query for multi values in one field

纵然是瞬间 提交于 2021-01-29 09:28:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!