new QueryParser(.... ).parse (somequery);
it works only for string indexed fields. Say i have a field called count where count is a integer field (
In Lucene 6, the protected method QueryParser#getRangeQuery still exists with the argument list (String fieldName, String low, String high, boolean startInclusive, boolean endInclusive)
, and overriding it to interpret the range as a numeric range is indeed possible, as long as that information is indexed using one of the new Point
fields.
When indexing your field:
document.add(new FloatPoint("_point_count", value)); // index for efficient range based retrieval
document.add(new StoredField("count", value)); // if you need to store the value itself
At your custom query parser (extending queryparser.classic.QueryParser
), override the method with something like this:
@Override
protected Query getRangeQuery(String field, String low, String high, boolean startInclusive, boolean endInclusive) throws ParseException
{
if («isNumericField»(field)) // context dependent
{
final String pointField = "_point_" + field;
return FloatPoint.newRangeQuery(pointField,
Float.parseFloat(low),
Float.parseFloat(high));
}
return super.getRangeQuery(field, low, high, startInclusive, endInclusive);
}