org.elasticsearch.search.suggest.phrase.PhraseSuggestion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :distribution:archives:integ-test-zip
/*
* 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.search.suggest.phrase;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.Suggest.Suggestion;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
/**
* Suggestion entry returned from the {@link PhraseSuggester}.
*/
public class PhraseSuggestion extends Suggest.Suggestion {
@Deprecated
public static final int TYPE = 3;
public PhraseSuggestion(String name, int size) {
super(name, size);
}
public PhraseSuggestion(StreamInput in) throws IOException {
super(in);
}
@Override
public String getWriteableName() {
return PhraseSuggestionBuilder.SUGGESTION_NAME;
}
@Override
public int getWriteableType() {
return TYPE;
}
@Override
protected Entry newEntry(StreamInput in) throws IOException {
return new Entry(in);
}
public static PhraseSuggestion fromXContent(XContentParser parser, String name) throws IOException {
PhraseSuggestion suggestion = new PhraseSuggestion(name, -1);
parseEntries(parser, suggestion, PhraseSuggestion.Entry::fromXContent);
return suggestion;
}
public static class Entry extends Suggestion.Entry {
protected double cutoffScore = Double.MIN_VALUE;
public Entry(Text text, int offset, int length, double cutoffScore) {
super(text, offset, length);
this.cutoffScore = cutoffScore;
}
public Entry(Text text, int offset, int length) {
super(text, offset, length);
}
Entry() {}
public Entry(StreamInput in) throws IOException {
super(in);
cutoffScore = in.readDouble();
}
/**
* @return cutoff score for suggestions. input term score * confidence for phrase suggest, 0 otherwise
*/
public double getCutoffScore() {
return cutoffScore;
}
@Override
protected void merge(Suggestion.Entry