0

I have indexed IntPointField using lucene which I am able to fetch using below query:

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

its fetching the relevant correctly.

If i build the query using parse it doesn't work

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

I checked the string representation of both the query they look identical as below

field1:[0 TO 40]

Does anyone know what am I doing wrong?

akram
  • 157
  • 1
  • 15
  • @see [Apache Lucene 6 QueryParser range query is not working with IntPoint](https://stackoverflow.com/questions/45516870/apache-lucene-6-queryparser-range-query-is-not-working-with-intpoint) - and [How to use QueryParser for Lucene range queries (IntPoint/LongPoint)](https://stackoverflow.com/q/64714307/2529954) – EricLavault Dec 12 '21 at 15:20

1 Answers1

1

IntPoint field requires custom query paser. The below solves the problem

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);
akram
  • 157
  • 1
  • 15