【问题标题】:Lucene queryParser builds the query correctly but search doesn't wrokLucene queryParser 正确构建查询,但搜索不起作用
【发布时间】:2022-01-16 06:54:39
【问题描述】:

我已经使用 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]

有谁知道我做错了什么?

【问题讨论】:

标签: java elasticsearch solr lucene


【解决方案1】:

IntPoint 字段需要自定义查询解析器。 下面解决问题

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);

【讨论】:

    猜你喜欢
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    相关资源
    最近更新 更多