Example usage for org.apache.lucene.search.suggest.analyzing FreeTextSuggester DEFAULT_GRAMS

List of usage examples for org.apache.lucene.search.suggest.analyzing FreeTextSuggester DEFAULT_GRAMS

Introduction

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

Prototype

int DEFAULT_GRAMS

To view the source code for org.apache.lucene.search.suggest.analyzing FreeTextSuggester DEFAULT_GRAMS.

Click Source Link

Document

By default we use a bigram model.

Usage

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

License:Apache License

@Override
public Lookup create(NamedList params, SolrCore core) {
    Object fieldTypeName = params.get(QUERY_ANALYZER);
    if (fieldTypeName == null) {
        throw new IllegalArgumentException(
                "Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
    }//from   w ww .j  a v a  2  s  . 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();

    int grams = (params.get(NGRAMS) != null) ? Integer.parseInt(params.get(NGRAMS).toString())
            : FreeTextSuggester.DEFAULT_GRAMS;

    byte separator = (params.get(SEPARATOR) != null)
            ? params.get(SEPARATOR).toString().getBytes(StandardCharsets.UTF_8)[0]
            : FreeTextSuggester.DEFAULT_SEPARATOR;

    return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}