Example usage for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester DEFAULT_MIN_PREFIX_CHARS

List of usage examples for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester DEFAULT_MIN_PREFIX_CHARS

Introduction

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

Prototype

int DEFAULT_MIN_PREFIX_CHARS

To view the source code for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester DEFAULT_MIN_PREFIX_CHARS.

Click Source Link

Document

Default minimum number of leading characters before PrefixQuery is used (4).

Usage

From source file:org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory.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 w  ww .ja  va 2 s .c  om*/
    FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
    Analyzer indexAnalyzer = ft.getAnalyzer();
    Analyzer queryAnalyzer = ft.getQueryAnalyzer();

    // optional parameters

    String indexPath = params.get(INDEX_PATH) != null ? params.get(INDEX_PATH).toString() : DEFAULT_INDEX_PATH;

    int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
            ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
            : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

    try {
        return new AnalyzingInfixSuggester(core.getSolrConfig().luceneMatchVersion, new File(indexPath),
                indexAnalyzer, queryAnalyzer, minPrefixChars);
    } catch (IOException e) {
        throw new RuntimeException();
    }
}

From source file:org.apache.solr.spelling.suggest.fst.BlendedInfixLookupFactory.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 w  w  w.  ja  va 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();

    // optional parameters

    String indexPath = params.get(INDEX_PATH) != null ? params.get(INDEX_PATH).toString() : DEFAULT_INDEX_PATH;
    if (new File(indexPath).isAbsolute() == false) {
        indexPath = core.getDataDir() + File.separator + indexPath;
    }

    int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
            ? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
            : AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;

    BlenderType blenderType = getBlenderType(params.get(BLENDER_TYPE));

    int numFactor = params.get(NUM_FACTOR) != null ? Integer.parseInt(params.get(NUM_FACTOR).toString())
            : BlendedInfixSuggester.DEFAULT_NUM_FACTOR;

    try {
        return new BlendedInfixSuggester(core.getSolrConfig().luceneMatchVersion,
                FSDirectory.open(new File(indexPath)), indexAnalyzer, queryAnalyzer, minPrefixChars,
                blenderType, numFactor) {
            @Override
            public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num,
                    boolean allTermsRequired, boolean doHighlight) throws IOException {
                List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired, doHighlight);
                if (doHighlight) {
                    List<LookupResult> res2 = new ArrayList<>();
                    for (LookupResult hit : res) {
                        res2.add(new LookupResult(hit.highlightKey.toString(), hit.highlightKey, hit.value,
                                hit.payload, hit.contexts));
                    }
                    res = res2;
                }

                return res;
            }
        };
    } catch (IOException e) {
        throw new RuntimeException();
    }
}