use of org.apache.lucene.queryparser.flexible.standard.config.PointsConfig in project lucene-solr by apache.
the class TestPointQueryParser method testIntegers.
public void testIntegers() throws Exception {
StandardQueryParser parser = new StandardQueryParser();
Map<String, PointsConfig> pointsConfig = new HashMap<>();
pointsConfig.put("intField", new PointsConfig(NumberFormat.getIntegerInstance(Locale.ROOT), Integer.class));
parser.setPointsConfigMap(pointsConfig);
assertEquals(IntPoint.newRangeQuery("intField", 1, 3), parser.parse("intField:[1 TO 3]", "body"));
assertEquals(IntPoint.newRangeQuery("intField", 1, 1), parser.parse("intField:1", "body"));
}
use of org.apache.lucene.queryparser.flexible.standard.config.PointsConfig in project lucene-solr by apache.
the class PointQueryNodeProcessor method postProcessNode.
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
if (node instanceof FieldQueryNode && !(node.getParent() instanceof RangeQueryNode)) {
QueryConfigHandler config = getQueryConfigHandler();
if (config != null) {
FieldQueryNode fieldNode = (FieldQueryNode) node;
FieldConfig fieldConfig = config.getFieldConfig(fieldNode.getFieldAsString());
if (fieldConfig != null) {
PointsConfig numericConfig = fieldConfig.get(ConfigurationKeys.POINTS_CONFIG);
if (numericConfig != null) {
NumberFormat numberFormat = numericConfig.getNumberFormat();
String text = fieldNode.getTextAsString();
Number number = null;
if (text.length() > 0) {
try {
number = numberFormat.parse(text);
} catch (ParseException e) {
throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode.getTextAsString(), numberFormat.getClass().getCanonicalName()), e);
}
if (Integer.class.equals(numericConfig.getType())) {
number = number.intValue();
} else if (Long.class.equals(numericConfig.getType())) {
number = number.longValue();
} else if (Double.class.equals(numericConfig.getType())) {
number = number.doubleValue();
} else if (Float.class.equals(numericConfig.getType())) {
number = number.floatValue();
}
} else {
throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.getFieldAsString()));
}
PointQueryNode lowerNode = new PointQueryNode(fieldNode.getField(), number, numberFormat);
PointQueryNode upperNode = new PointQueryNode(fieldNode.getField(), number, numberFormat);
return new PointRangeQueryNode(lowerNode, upperNode, true, true, numericConfig);
}
}
}
}
return node;
}
Aggregations