Search in sources :

Example 1 with CompletionQuery

use of org.apache.lucene.search.suggest.document.CompletionQuery in project elasticsearch by elastic.

the class CompletionSuggestionContext method toQuery.

CompletionQuery toQuery() {
    CompletionFieldMapper.CompletionFieldType fieldType = getFieldType();
    final CompletionQuery query;
    if (getPrefix() != null) {
        query = createCompletionQuery(getPrefix(), fieldType);
    } else if (getRegex() != null) {
        if (fuzzyOptions != null) {
            throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex");
        }
        if (regexOptions == null) {
            regexOptions = RegexOptions.builder().build();
        }
        query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(), regexOptions.getMaxDeterminizedStates());
    } else if (getText() != null) {
        query = createCompletionQuery(getText(), fieldType);
    } else {
        throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined");
    }
    if (fieldType.hasContextMappings()) {
        ContextMappings contextMappings = fieldType.getContextMappings();
        return contextMappings.toContextQuery(query, queryContexts);
    }
    return query;
}
Also used : CompletionFieldMapper(org.elasticsearch.index.mapper.CompletionFieldMapper) ContextMappings(org.elasticsearch.search.suggest.completion.context.ContextMappings) CompletionQuery(org.apache.lucene.search.suggest.document.CompletionQuery)

Aggregations

CompletionQuery (org.apache.lucene.search.suggest.document.CompletionQuery)1 CompletionFieldMapper (org.elasticsearch.index.mapper.CompletionFieldMapper)1 ContextMappings (org.elasticsearch.search.suggest.completion.context.ContextMappings)1