use of org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode 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