簡體   English   中英

Lucene queryParser 正確構建查詢,但搜索無法正常工作

[英]Lucene queryParser builds the query correctly but search doesn't wrok

我已經使用 lucene 對 IntPointField 進行了索引,我可以使用以下查詢獲取它:

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

它正確地獲取相關信息。

如果我使用解析構建查詢它不起作用

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

我檢查了兩個查詢的字符串表示形式,它們看起來相同,如下所示

field1:[0 TO 40]

有誰知道我做錯了什么?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM