Example usage for org.apache.lucene.search.suggest DocumentValueSourceDictionary DocumentValueSourceDictionary

List of usage examples for org.apache.lucene.search.suggest DocumentValueSourceDictionary DocumentValueSourceDictionary

Introduction

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

Prototype

public DocumentValueSourceDictionary(IndexReader reader, String field, LongValuesSource weightsValueSource,
        String payload) 

Source Link

Document

Creates a new dictionary with the contents of the fields named field for the terms, payloadField for the corresponding payloads and uses the weightsValueSource supplied to determine the score.

Usage

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

License:Apache License

@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
    if (params == null) {
        // should not happen; implies setParams was not called
        throw new IllegalStateException("Value of params not set");
    }/*w  w w.  ja  v  a2  s.c  om*/

    String field = (String) params.get(FIELD);
    String payloadField = (String) params.get(PAYLOAD_FIELD);
    String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
    Set<SortField> sortFields = new HashSet<>();

    if (field == null) {
        throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
    }

    if (weightExpression == null) {
        throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
    }

    for (int i = 0; i < params.size(); i++) {
        if (params.getName(i).equals(SORT_FIELD)) {
            String sortFieldName = (String) params.getVal(i);

            SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);

            if (sortFieldType == null) {
                throw new IllegalArgumentException(sortFieldName
                        + " could not be mapped to any appropriate type" + " [long, int, float, double]");
            }

            SortField sortField = new SortField(sortFieldName, sortFieldType);
            sortFields.add(sortField);
        }
    }

    return new DocumentValueSourceDictionary(searcher.getIndexReader(), field,
            fromExpression(weightExpression, sortFields), payloadField);
}