Lucene query解析器正确构建查询,但搜索无法破坏



我已经使用lucene为IntPointField编制了索引,我可以使用以下查询获取:

Query query = IntPoint.newRangeQuery("field1", 0, 40);
TopDocs topDocs = searcher.search(query);
System.out.println(topDocs.totalHits);

它正确地获取了相关信息。

如果我使用parse构建查询,那么就不起作用

Query query = new QueryParser(Version.LUCENE_8_11_0.toString(), new StandardAnalyzer()).parse("field1:[0 TO 40]");

我检查了两个查询的字符串表示,它们看起来完全相同,如下

field1:[0 TO 40]

有人知道我做错了什么吗?

IntPoint字段需要自定义查询paser。以下解决了问题

StandardQueryParser parser = new StandardQueryParser();
parser.setAnalyzer(new StandardAnalyzer());
PointsConfig indexableFields = new PointsConfig(new DecimalFormat(), Integer.class);
Map<String, PointsConfig> indexableFieldMap = new HashMap<>();
pointsConfigMap.put("field1", indexableFields);
parser.setPointsConfigMap(indexableFieldMap);

最新更新