Example usage for org.apache.lucene.search.suggest.analyzing AnalyzingSuggester EXACT_FIRST

List of usage examples for org.apache.lucene.search.suggest.analyzing AnalyzingSuggester EXACT_FIRST

Introduction

In this page you can find the example usage for org.apache.lucene.search.suggest.analyzing AnalyzingSuggester EXACT_FIRST.

Prototype

int EXACT_FIRST

To view the source code for org.apache.lucene.search.suggest.analyzing AnalyzingSuggester EXACT_FIRST.

Click Source Link

Document

Include this flag in the options parameter to #AnalyzingSuggester(Directory,String,Analyzer,Analyzer,int,int,int,boolean) to always return the exact match first, regardless of score.

Usage

From source file:org.apache.solr.spelling.suggest.fst.AnalyzingLookupFactory.java

License:Apache License

@Override
public Lookup create(NamedList params, SolrCore core) {
    // mandatory parameter
    Object fieldTypeName = params.get(QUERY_ANALYZER);
    if (fieldTypeName == null) {
        throw new IllegalArgumentException(
                "Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
    }/*from   www .  ja v  a  2s .  c  om*/
    FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
    Analyzer indexAnalyzer = ft.getAnalyzer();
    Analyzer queryAnalyzer = ft.getQueryAnalyzer();

    // optional parameters

    boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
            ? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
            : true;

    boolean preserveSep = params.get(PRESERVE_SEP) != null
            ? Boolean.valueOf(params.get(PRESERVE_SEP).toString())
            : true;

    int flags = 0;
    if (exactMatchFirst) {
        flags |= AnalyzingSuggester.EXACT_FIRST;
    }
    if (preserveSep) {
        flags |= AnalyzingSuggester.PRESERVE_SEP;
    }

    int maxSurfaceFormsPerAnalyzedForm = params.get(MAX_SURFACE_FORMS) != null
            ? Integer.parseInt(params.get(MAX_SURFACE_FORMS).toString())
            : 256;

    int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null
            ? Integer.parseInt(params.get(MAX_EXPANSIONS).toString())
            : -1;

    boolean preservePositionIncrements = params.get(PRESERVE_POSITION_INCREMENTS) != null
            ? Boolean.valueOf(params.get(PRESERVE_POSITION_INCREMENTS).toString())
            : false;

    return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm,
            maxGraphExpansions, preservePositionIncrements);
}

From source file:org.apache.solr.spelling.suggest.SmartAnalyzingLookupFactory.java

License:Apache License

@Override
public Lookup create(NamedList params, SolrCore core) {
    System.out.println("====> SmartAnalyzingLookupFactory.create() : Lookup called");

    // mandatory parameter
    Object fieldTypeName = params.get(QUERY_ANALYZER);
    if (fieldTypeName == null) {
        throw new IllegalArgumentException(
                "Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
    }/*w w w . ja v a 2s.  c  o m*/
    FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
    if (ft == null) {
        throw new IllegalArgumentException(
                "Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
    }

    Analyzer indexAnalyzer = ft.getIndexAnalyzer();
    Analyzer queryAnalyzer = ft.getQueryAnalyzer();

    // optional parameters

    boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
            ? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
            : true;

    boolean preserveSep = params.get(PRESERVE_SEP) != null
            ? Boolean.valueOf(params.get(PRESERVE_SEP).toString())
            : true;

    int flags = 0;
    if (exactMatchFirst) {
        flags |= AnalyzingSuggester.EXACT_FIRST;
    }
    if (preserveSep) {
        flags |= AnalyzingSuggester.PRESERVE_SEP;
    }

    int maxSurfaceFormsPerAnalyzedForm = params.get(MAX_SURFACE_FORMS) != null
            ? Integer.parseInt(params.get(MAX_SURFACE_FORMS).toString())
            : 256;

    int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null
            ? Integer.parseInt(params.get(MAX_EXPANSIONS).toString())
            : -1;

    boolean preservePositionIncrements = params.get(PRESERVE_POSITION_INCREMENTS) != null
            ? Boolean.valueOf(params.get(PRESERVE_POSITION_INCREMENTS).toString())
            : false;

    return new SmartAnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm,
            maxGraphExpansions, preservePositionIncrements);
}