Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.index.mapper;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.suggest.document.CompletionAnalyzer;
import org.apache.lucene.search.suggest.document.CompletionQuery;
import org.apache.lucene.search.suggest.document.FuzzyCompletionQuery;
import org.apache.lucene.search.suggest.document.PrefixCompletionQuery;
import org.apache.lucene.search.suggest.document.RegexCompletionQuery;
import org.apache.lucene.search.suggest.document.SuggestField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.search.suggest.completion.CompletionSuggester;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
import org.elasticsearch.search.suggest.completion.context.ContextMappings;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.FilterXContentParser;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentLocation;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParser.NumberType;
import org.elasticsearch.xcontent.XContentParser.Token;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.support.MapXContentParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Mapper for completion field. The field values are indexed as a weighted FST for
* fast auto-completion/search-as-you-type functionality.
*
* Type properties:
*
*
"analyzer": "simple", (default)
*
"search_analyzer": "simple", (default)
*
"preserve_separators" : true, (default)
*
"preserve_position_increments" : true (default)
*
"min_input_length": 50 (default)
*
"contexts" : CONTEXTS
*
* see {@link ContextMappings#load(Object)} for CONTEXTS
* see {@link #parse(DocumentParserContext)} for acceptable inputs for indexing
*
* This field type constructs completion queries that are run
* against the weighted FST index by the {@link CompletionSuggester}.
* This field can also be extended to add search criteria to suggestions
* for query-time filtering and boosting (see {@link ContextMappings}
*/
public class CompletionFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "completion";
/**
* Maximum allowed number of completion contexts in a mapping.
*/
static final int COMPLETION_CONTEXTS_LIMIT = 10;
@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(leafName(), builder.defaultAnalyzer, builder.indexVersionCreated).init(this);
}
public static class Defaults {
public static final FieldType FIELD_TYPE;
static {
final FieldType ft = new FieldType();
ft.setTokenized(true);
ft.setStored(false);
ft.setStoreTermVectors(false);
ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
ft.setOmitNorms(true);
FIELD_TYPE = freezeAndDeduplicateFieldType(ft);
}
public static final boolean DEFAULT_PRESERVE_SEPARATORS = true;
public static final boolean DEFAULT_POSITION_INCREMENTS = true;
public static final int DEFAULT_MAX_INPUT_LENGTH = 50;
}
public static class Fields {
// Content field names
public static final String CONTENT_FIELD_NAME_INPUT = "input";
public static final String CONTENT_FIELD_NAME_WEIGHT = "weight";
public static final String CONTENT_FIELD_NAME_CONTEXTS = "contexts";
}
private static Builder builder(FieldMapper in) {
return ((CompletionFieldMapper) in).builder;
}
/**
* Builder for {@link CompletionFieldMapper}
*/
public static class Builder extends FieldMapper.Builder {
private final Parameter analyzer;
private final Parameter searchAnalyzer;
private final Parameter preserveSeparators = Parameter.boolParam(
"preserve_separators",
false,
m -> builder(m).preserveSeparators.get(),
Defaults.DEFAULT_PRESERVE_SEPARATORS
).alwaysSerialize();
private final Parameter preservePosInc = Parameter.boolParam(
"preserve_position_increments",
false,
m -> builder(m).preservePosInc.get(),
Defaults.DEFAULT_POSITION_INCREMENTS
).alwaysSerialize();
private final Parameter contexts = new Parameter<>(
"contexts",
false,
() -> null,
(n, c, o) -> ContextMappings.load(o),
m -> builder(m).contexts.get(),
(b, n, c) -> {
if (c == null) {
return;
}
b.startArray(n);
c.toXContent(b, ToXContent.EMPTY_PARAMS);
b.endArray();
},
Objects::toString
);
private final Parameter maxInputLength = Parameter.intParam(
"max_input_length",
true,
m -> builder(m).maxInputLength.get(),
Defaults.DEFAULT_MAX_INPUT_LENGTH
).addDeprecatedName("max_input_len").addValidator(Builder::validateInputLength).alwaysSerialize();
private final Parameter