Search in sources :

Example 1 with FuzzyConfig

use of org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig in project lucene-solr by apache.

the class StandardQueryParser method setFuzzyPrefixLength.

/**
   * Set the prefix length for fuzzy queries. Default is 0.
   * 
   * @param fuzzyPrefixLength
   *          The fuzzyPrefixLength to set.
   */
@Override
public void setFuzzyPrefixLength(int fuzzyPrefixLength) {
    QueryConfigHandler config = getQueryConfigHandler();
    FuzzyConfig fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG);
    if (fuzzyConfig == null) {
        fuzzyConfig = new FuzzyConfig();
        config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig);
    }
    fuzzyConfig.setPrefixLength(fuzzyPrefixLength);
}
Also used : FuzzyConfig(org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler) StandardQueryConfigHandler(org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler)

Example 2 with FuzzyConfig

use of org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig in project lucene-solr by apache.

the class StandardQueryParser method setFuzzyMinSim.

/**
   * Set the minimum similarity for fuzzy queries. Default is defined on
   * {@link FuzzyQuery#defaultMinSimilarity}.
   */
@Override
public void setFuzzyMinSim(float fuzzyMinSim) {
    QueryConfigHandler config = getQueryConfigHandler();
    FuzzyConfig fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG);
    if (fuzzyConfig == null) {
        fuzzyConfig = new FuzzyConfig();
        config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig);
    }
    fuzzyConfig.setMinSimilarity(fuzzyMinSim);
}
Also used : FuzzyConfig(org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler) StandardQueryConfigHandler(org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler)

Example 3 with FuzzyConfig

use of org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig 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

QueryConfigHandler (org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler)3 FuzzyConfig (org.apache.lucene.queryparser.flexible.standard.config.FuzzyConfig)3 StandardQueryConfigHandler (org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler)2 Analyzer (org.apache.lucene.analysis.Analyzer)1 FuzzyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode)1