Projects >> elasticsearch >>7cae28f96ad35ff2dc56d8df866e601a0a187bba

Chunk
Conflicting content
        CandidateGenerator fromXContent(QueryParseContext parseContext) throws IOException;
    }
<<<<<<< HEAD

    /**
     *
     *
     */
    public static final class DirectCandidateGenerator extends CandidateGenerator {
        private final String field;
        private String preFilter;
        private String postFilter;
        private String suggestMode;
        private Float accuracy;
        private Integer size;
        private String sort;
        private String stringDistance;
        private Integer maxEdits;
        private Integer maxInspections;
        private Float maxTermFreq;
        private Integer prefixLength;
        private Integer minWordLength;
        private Float minDocFreq;

        /**
         * @param field Sets from what field to fetch the candidate suggestions from.
         */
        public DirectCandidateGenerator(String field) {
            super("direct_generator");
            this.field = field;
        }

        /**
         * The global suggest mode controls what suggested terms are included or
         * controls for what suggest text tokens, terms should be suggested for.
         * Three possible values can be specified:
         * 
    *
  1. missing - Only suggest terms in the suggest text * that aren't in the index. This is the default. *
  2. popular - Only suggest terms that occur in more docs * then the original suggest text term. *
  3. always - Suggest any matching suggest terms based on * tokens in the suggest text. *
*/ public DirectCandidateGenerator suggestMode(String suggestMode) { this.suggestMode = suggestMode; return this; } /** * Sets how similar the suggested terms at least need to be compared to * the original suggest text tokens. A value between 0 and 1 can be * specified. This value will be compared to the string distance result * of each candidate spelling correction. *

* Default is 0.5 */ public DirectCandidateGenerator accuracy(float accuracy) { this.accuracy = accuracy; return this; } /** * Sets the maximum suggestions to be returned per suggest text term. */ public DirectCandidateGenerator size(int size) { if (size <= 0) { throw new IllegalArgumentException("Size must be positive"); } this.size = size; return this; } /** * Sets how to sort the suggest terms per suggest text token. Two * possible values: *

    *
  1. score - Sort should first be based on score, then * document frequency and then the term itself. *
  2. frequency - Sort should first be based on document * frequency, then scotr and then the term itself. *
*

* What the score is depends on the suggester being used. */ public DirectCandidateGenerator sort(String sort) { this.sort = sort; return this; } /** * Sets what string distance implementation to use for comparing how * similar suggested terms are. Four possible values can be specified: *

    *
  1. internal - This is the default and is based on * damerau_levenshtein, but highly optimized for comparing * string distance for terms inside the index. *
  2. damerau_levenshtein - String distance algorithm * based on Damerau-Levenshtein algorithm. *
  3. levenstein - String distance algorithm based on * Levenstein edit distance algorithm. *
  4. jarowinkler - String distance algorithm based on * Jaro-Winkler algorithm. *
  5. ngram - String distance algorithm based on character * n-grams. *
*/ public DirectCandidateGenerator stringDistance(String stringDistance) { this.stringDistance = stringDistance; return this; } /** * Sets the maximum edit distance candidate suggestions can have in * order to be considered as a suggestion. Can only be a value between 1 * and 2. Any other value result in an bad request error being thrown. * Defaults to 2. */ public DirectCandidateGenerator maxEdits(Integer maxEdits) { this.maxEdits = maxEdits; return this; } /** * A factor that is used to multiply with the size in order to inspect * more candidate suggestions. Can improve accuracy at the cost of * performance. Defaults to 5. */ public DirectCandidateGenerator maxInspections(Integer maxInspections) { this.maxInspections = maxInspections; return this; } /** * Sets a maximum threshold in number of documents a suggest text token * can exist in order to be corrected. Can be a relative percentage * number (e.g 0.4) or an absolute number to represent document * frequencies. If an value higher than 1 is specified then fractional * can not be specified. Defaults to 0.01. *

* This can be used to exclude high frequency terms from being * suggested. High frequency terms are usually spelled correctly on top * of this this also improves the suggest performance. */ public DirectCandidateGenerator maxTermFreq(float maxTermFreq) { this.maxTermFreq = maxTermFreq; return this; } /** * Sets the number of minimal prefix characters that must match in order * be a candidate suggestion. Defaults to 1. Increasing this number * improves suggest performance. Usually misspellings don't occur in the * beginning of terms. */ public DirectCandidateGenerator prefixLength(int prefixLength) { this.prefixLength = prefixLength; return this; } /** * The minimum length a suggest text term must have in order to be * corrected. Defaults to 4. */ public DirectCandidateGenerator minWordLength(int minWordLength) { this.minWordLength = minWordLength; return this; } /** * Sets a minimal threshold in number of documents a suggested term * should appear in. This can be specified as an absolute number or as a * relative percentage of number of documents. This can improve quality * by only suggesting high frequency terms. Defaults to 0f and is not * enabled. If a value higher than 1 is specified then the number cannot * be fractional. */ public DirectCandidateGenerator minDocFreq(float minDocFreq) { this.minDocFreq = minDocFreq; return this; } /** * Sets a filter (analyzer) that is applied to each of the tokens passed to this candidate generator. * This filter is applied to the original token before candidates are generated. */ public DirectCandidateGenerator preFilter(String preFilter) { this.preFilter = preFilter; return this; } /** * Sets a filter (analyzer) that is applied to each of the generated tokens * before they are passed to the actual phrase scorer. */ public DirectCandidateGenerator postFilter(String postFilter) { this.postFilter = postFilter; return this; } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (field != null) { builder.field("field", field); } if (suggestMode != null) { builder.field("suggest_mode", suggestMode); } if (accuracy != null) { builder.field("accuracy", accuracy); } if (size != null) { builder.field("size", size); } if (sort != null) { builder.field("sort", sort); } if (stringDistance != null) { builder.field("string_distance", stringDistance); } if (maxEdits != null) { builder.field("max_edits", maxEdits); } if (maxInspections != null) { builder.field("max_inspections", maxInspections); } if (maxTermFreq != null) { builder.field("max_term_freq", maxTermFreq); } if (prefixLength != null) { builder.field("prefix_length", prefixLength); } if (minWordLength != null) { builder.field("min_word_length", minWordLength); } if (minDocFreq != null) { builder.field("min_doc_freq", minDocFreq); } if (preFilter != null) { builder.field("pre_filter", preFilter); } if (postFilter != null) { builder.field("post_filter", postFilter); } builder.endObject(); return builder; } } @Override public String getWriteableName() { return SUGGESTION_NAME; } @Override public void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalFloat(maxErrors); out.writeOptionalFloat(realWordErrorLikelihood); out.writeOptionalFloat(confidence); out.writeOptionalVInt(gramSize); // NORELEASE model.writeTo(); out.writeOptionalBoolean(forceUnigrams); out.writeOptionalVInt(tokenLimit); out.writeOptionalString(preTag); out.writeOptionalString(postTag); out.writeOptionalString(separator); if (collateQuery != null) { out.writeBoolean(true); collateQuery.writeTo(out); } else { out.writeBoolean(false); } out.writeMap(collateParams); out.writeOptionalBoolean(collatePrune); // NORELEASE write Map> generators = new HashMap<>(); } @Override public PhraseSuggestionBuilder doReadFrom(StreamInput in, String name) throws IOException { PhraseSuggestionBuilder builder = new PhraseSuggestionBuilder(name); builder.maxErrors = in.readOptionalFloat(); builder.realWordErrorLikelihood = in.readOptionalFloat(); builder.confidence = in.readOptionalFloat(); builder.gramSize = in.readOptionalVInt(); // NORELEASE read model builder.forceUnigrams = in.readOptionalBoolean(); builder.tokenLimit = in.readOptionalVInt(); builder.preTag = in.readOptionalString(); builder.postTag = in.readOptionalString(); builder.separator = in.readOptionalString(); if (in.readBoolean()) { builder.collateQuery = Template.readTemplate(in); } builder.collateParams = in.readMap(); builder.collatePrune = in.readOptionalBoolean(); // NORELEASE read Map> generators; return builder; } @Override protected boolean doEquals(PhraseSuggestionBuilder other) { return Objects.equals(maxErrors, other.maxErrors) && Objects.equals(separator, other.separator) && Objects.equals(realWordErrorLikelihood, other.realWordErrorLikelihood) && Objects.equals(confidence, other.confidence) && // NORELEASE Objects.equals(generator, other.generator) && Objects.equals(gramSize, other.gramSize) && // NORELEASE Objects.equals(model, other.model) && Objects.equals(forceUnigrams, other.forceUnigrams) && Objects.equals(tokenLimit, other.tokenLimit) && Objects.equals(preTag, other.preTag) && Objects.equals(postTag, other.postTag) && Objects.equals(collateQuery, other.collateQuery) && Objects.equals(collateParams, other.collateParams) && Objects.equals(collatePrune, other.collatePrune); } @Override protected int doHashCode() { return Objects.hash(maxErrors, separator, realWordErrorLikelihood, confidence, /** NORELEASE generators, */ gramSize, /** NORELEASE model, */ forceUnigrams, tokenLimit, preTag, postTag, collateQuery, collateParams, collatePrune); } ======= >>>>>>> 220bf7bd4b5f03e8415eda4b14a8ba2308692661 }

Solution content
    @Override
    public String getWriteableName() {
        return SUGGESTION_NAME;
    }

    @Override
    public void doWriteTo(StreamOutput out) throws IOException {
        out.writeOptionalFloat(maxErrors);
        out.writeOptionalFloat(realWordErrorLikelihood);
        out.writeOptionalFloat(confidence);
        out.writeOptionalVInt(gramSize);
        // NORELEASE model.writeTo();
        out.writeOptionalBoolean(forceUnigrams);
        out.writeOptionalVInt(tokenLimit);
        out.writeOptionalString(preTag);
        out.writeOptionalString(postTag);
        out.writeOptionalString(separator);
        if (collateQuery != null) {
            out.writeBoolean(true);
            collateQuery.writeTo(out);
        } else {
            out.writeBoolean(false);
        }
        out.writeMap(collateParams);
        out.writeOptionalBoolean(collatePrune);
        // NORELEASE write Map> generators = new HashMap<>();
    }

    @Override
    public PhraseSuggestionBuilder doReadFrom(StreamInput in, String name) throws IOException {
        PhraseSuggestionBuilder builder = new PhraseSuggestionBuilder(name);
        builder.maxErrors = in.readOptionalFloat();
        builder.realWordErrorLikelihood = in.readOptionalFloat();
        builder.confidence = in.readOptionalFloat();
        builder.gramSize = in.readOptionalVInt();
        // NORELEASE read model
        builder.forceUnigrams = in.readOptionalBoolean();
        builder.tokenLimit = in.readOptionalVInt();
        builder.preTag = in.readOptionalString();
        builder.postTag = in.readOptionalString();
        builder.separator = in.readOptionalString();
        if (in.readBoolean()) {
            builder.collateQuery = Template.readTemplate(in);
        }
        builder.collateParams = in.readMap();
        builder.collatePrune = in.readOptionalBoolean();
        // NORELEASE read Map> generators;
        return builder;
    }

    @Override
    protected boolean doEquals(PhraseSuggestionBuilder other) {
        return Objects.equals(maxErrors, other.maxErrors) &&
                Objects.equals(separator, other.separator) &&
                Objects.equals(realWordErrorLikelihood, other.realWordErrorLikelihood) &&
                Objects.equals(confidence, other.confidence) &&
                // NORELEASE Objects.equals(generator, other.generator) &&
                Objects.equals(gramSize, other.gramSize) &&
                // NORELEASE Objects.equals(model, other.model) &&
                Objects.equals(forceUnigrams, other.forceUnigrams) &&
                Objects.equals(tokenLimit, other.tokenLimit) &&
                Objects.equals(preTag, other.preTag) &&
                Objects.equals(postTag, other.postTag) &&
                Objects.equals(collateQuery, other.collateQuery) &&
                Objects.equals(collateParams, other.collateParams) &&
                Objects.equals(collatePrune, other.collatePrune);
    }

    @Override
    protected int doHashCode() {
        return Objects.hash(maxErrors, separator, realWordErrorLikelihood, confidence,
                /** NORELEASE generators, */
                gramSize,
                /** NORELEASE model, */
                forceUnigrams, tokenLimit, preTag, postTag,
                collateQuery, collateParams, collatePrune);
    }

    /**
     * {@link CandidateGenerator} interface.
     */
    public interface CandidateGenerator extends ToXContent {
        String getType();

        CandidateGenerator fromXContent(QueryParseContext parseContext) throws IOException;
    }
}
File
PhraseSuggestionBuilder.java
Developer's decision
Manual
Kind of conflict
Annotation
Class declaration
Comment
Method declaration
Chunk
Conflicting content
import org.elasticsearch.script.mustache.MustachePlugin;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder;
<<<<<<< HEAD
import org.elasticsearch.search.suggest.SuggestionBuilder;
=======
import org.elasticsearch.search.suggest.SuggestBuilder.SuggestionBuilder;
import org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder;
>>>>>>> 220bf7bd4b5f03e8415eda4b14a8ba2308692661
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder;
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
import org.elasticsearch.test.ESIntegTestCase;
Solution content
import org.elasticsearch.script.mustache.MustachePlugin;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.search.suggest.SuggestionBuilder;
import org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder;
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder;
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
import org.elasticsearch.test.ESIntegTestCase;
File
SuggestSearchTests.java
Developer's decision
Combination
Kind of conflict
Import