use of org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler 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;
}
use of org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler in project lucene-solr by apache.
the class BoostQueryNodeProcessor method postProcessNode.
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
if (node instanceof FieldableNode && (node.getParent() == null || !(node.getParent() instanceof FieldableNode))) {
FieldableNode fieldNode = (FieldableNode) node;
QueryConfigHandler config = getQueryConfigHandler();
if (config != null) {
CharSequence field = fieldNode.getField();
FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field));
if (fieldConfig != null) {
Float boost = fieldConfig.get(ConfigurationKeys.BOOST);
if (boost != null) {
return new BoostQueryNode(node, boost);
}
}
}
}
return node;
}
use of org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler in project lucene-solr by apache.
the class FuzzyQueryNodeProcessor method preProcessNode.
@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
if (node instanceof FuzzyQueryNode) {
FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) node;
QueryConfigHandler config = getQueryConfigHandler();
Analyzer analyzer = getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
if (analyzer != null) {
// because we call utf8ToString, this will only work with the default TermToBytesRefAttribute
String text = fuzzyNode.getTextAsString();
text = analyzer.normalize(fuzzyNode.getFieldAsString(), text).utf8ToString();
fuzzyNode.setText(text);
}
FuzzyConfig fuzzyConfig = null;
if ((fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG)) != null) {
fuzzyNode.setPrefixLength(fuzzyConfig.getPrefixLength());
if (fuzzyNode.getSimilarity() < 0) {
fuzzyNode.setSimilarity(fuzzyConfig.getMinSimilarity());
}
} else if (fuzzyNode.getSimilarity() < 0) {
throw new IllegalArgumentException("No FUZZY_CONFIG set in the config");
}
}
return node;
}
Aggregations