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

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?


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