Search in sources :

Example 6 with FuzzyQueryNode

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;
}
Also used : FuzzyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode) FuzzyConfig(org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler) Analyzer(org.apache.lucene.analysis.Analyzer)

Aggregations

FuzzyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode)6 FieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode)4 QuotedFieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode)4 BooleanQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode)3 GroupQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode)3 ModifierQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode)3 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)3 RegexpQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode)3 WildcardQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 CachingTokenFilter (org.apache.lucene.analysis.CachingTokenFilter)2 TokenStream (org.apache.lucene.analysis.TokenStream)2 CharTermAttribute (org.apache.lucene.analysis.tokenattributes.CharTermAttribute)2 PositionIncrementAttribute (org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute)2 BoostQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode)2 NoTokenFoundQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.NoTokenFoundQueryNode)2 RangeQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.RangeQueryNode)2