Remove unused empty constructors from suggestions classes (#37295)

We recently migrated suggestions to `Writeable`. That allows us to also
clean up empty constructors and methods that called them as they are no
longer needed. They are replaced by constructors that accept a
`StreamInput` instance.
This commit is contained in:
Luca Cavanna 2019-01-14 08:32:45 +01:00 committed by GitHub
parent a566bacbc8
commit d54f88f62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 108 deletions

View File

@ -77,11 +77,6 @@ public class CustomSuggestion extends Suggest.Suggestion<CustomSuggestion.Entry>
return dummy; return dummy;
} }
@Override
protected Entry newEntry() {
return new Entry();
}
@Override @Override
protected Entry newEntry(StreamInput in) throws IOException { protected Entry newEntry(StreamInput in) throws IOException {
return new Entry(in); return new Entry(in);
@ -123,11 +118,6 @@ public class CustomSuggestion extends Suggest.Suggestion<CustomSuggestion.Entry>
out.writeString(dummy); out.writeString(dummy);
} }
@Override
protected Option newOption() {
return new Option();
}
@Override @Override
protected Option newOption(StreamInput in) throws IOException { protected Option newOption(StreamInput in) throws IOException {
return new Option(in); return new Option(in);
@ -178,8 +168,6 @@ public class CustomSuggestion extends Suggest.Suggestion<CustomSuggestion.Entry>
private String dummy; private String dummy;
public Option() {}
public Option(Text text, float score, String dummy) { public Option(Text text, float score, String dummy) {
super(text, score); super(text, score);
this.dummy = dummy; this.dummy = dummy;

View File

@ -33,7 +33,6 @@ import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils; import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.search.RestSearchAction;
@ -46,7 +45,6 @@ import org.elasticsearch.search.suggest.term.TermSuggestion;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -78,10 +76,6 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
private Map<String, Suggestion<? extends Entry<? extends Option>>> suggestMap; private Map<String, Suggestion<? extends Entry<? extends Option>>> suggestMap;
private Suggest() {
this(Collections.emptyList());
}
public Suggest(List<Suggestion<? extends Entry<? extends Option>>> suggestions) { public Suggest(List<Suggestion<? extends Entry<? extends Option>>> suggestions) {
// we sort suggestions by their names to ensure iteration over suggestions are consistent // we sort suggestions by their names to ensure iteration over suggestions are consistent
// this is needed as we need to fill in suggestion docs in SearchPhaseController#sortDocs // this is needed as we need to fill in suggestion docs in SearchPhaseController#sortDocs
@ -259,16 +253,11 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
*/ */
public abstract static class Suggestion<T extends Suggestion.Entry> implements Iterable<T>, NamedWriteable, ToXContentFragment { public abstract static class Suggestion<T extends Suggestion.Entry> implements Iterable<T>, NamedWriteable, ToXContentFragment {
private static final String NAME = "suggestion";
public static final int TYPE = 0; public static final int TYPE = 0;
protected String name; protected final String name;
protected int size; protected final int size;
protected final List<T> entries = new ArrayList<>(5); protected final List<T> entries = new ArrayList<>(5);
protected Suggestion() {
}
public Suggestion(String name, int size) { public Suggestion(String name, int size) {
this.name = name; this.name = name;
this.size = size; // The suggested term size specified in request, only used for merging shard responses this.size = size; // The suggested term size specified in request, only used for merging shard responses
@ -380,7 +369,6 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
} }
} }
protected abstract T newEntry();
protected abstract T newEntry(StreamInput in) throws IOException; protected abstract T newEntry(StreamInput in) throws IOException;
@Override @Override
@ -608,7 +596,6 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
return Objects.hash(text, offset, length, options); return Objects.hash(text, offset, length, options);
} }
protected abstract O newOption();
protected abstract O newOption(StreamInput in) throws IOException; protected abstract O newOption(StreamInput in) throws IOException;
@Override @Override
@ -653,8 +640,8 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
public static final ParseField SCORE = new ParseField("score"); public static final ParseField SCORE = new ParseField("score");
public static final ParseField COLLATE_MATCH = new ParseField("collate_match"); public static final ParseField COLLATE_MATCH = new ParseField("collate_match");
private Text text; private final Text text;
private Text highlighted; private final Text highlighted;
private float score; private float score;
private Boolean collateMatch; private Boolean collateMatch;
@ -673,8 +660,6 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
this(text, null, score); this(text, null, score);
} }
public Option() {}
public Option(StreamInput in) throws IOException { public Option(StreamInput in) throws IOException {
text = in.readText(); text = in.readText();
score = in.readFloat(); score = in.readFloat();
@ -776,14 +761,6 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
@Override @Override
public String toString() { public String toString() {
try { return Strings.toString(this, true, true);
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return Strings.toString(builder);
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
} }
} }

View File

@ -71,11 +71,8 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
private boolean skipDuplicates; private boolean skipDuplicates;
public CompletionSuggestion() {
}
/** /**
* Ctr * Creates a completion suggestion given its name, size and whether it should skip duplicates
* @param name The name for the suggestions * @param name The name for the suggestions
* @param size The number of suggestions to return * @param size The number of suggestions to return
* @param skipDuplicates Whether duplicate suggestions should be filtered out * @param skipDuplicates Whether duplicate suggestions should be filtered out
@ -235,11 +232,6 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
return TYPE; return TYPE;
} }
@Override
protected Entry newEntry() {
return new Entry();
}
@Override @Override
protected Entry newEntry(StreamInput in) throws IOException { protected Entry newEntry(StreamInput in) throws IOException {
return new Entry(in); return new Entry(in);
@ -251,17 +243,12 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
super(text, offset, length); super(text, offset, length);
} }
Entry() {} private Entry() {}
public Entry(StreamInput in) throws IOException { public Entry(StreamInput in) throws IOException {
super(in); super(in);
} }
@Override
protected Option newOption() {
return new Option();
}
@Override @Override
protected Option newOption(StreamInput in) throws IOException { protected Option newOption(StreamInput in) throws IOException {
return new Option(in); return new Option(in);
@ -280,8 +267,8 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
} }
public static class Option extends Suggest.Suggestion.Entry.Option { public static class Option extends Suggest.Suggestion.Entry.Option {
private Map<String, Set<String>> contexts = Collections.emptyMap(); private final Map<String, Set<String>> contexts;
private ScoreDoc doc; private final ScoreDoc doc;
private SearchHit hit; private SearchHit hit;
public static final ParseField CONTEXTS = new ParseField("contexts"); public static final ParseField CONTEXTS = new ParseField("contexts");
@ -292,10 +279,6 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
this.contexts = Objects.requireNonNull(contexts, "context map cannot be null"); this.contexts = Objects.requireNonNull(contexts, "context map cannot be null");
} }
protected Option() {
super();
}
public Option(StreamInput in) throws IOException { public Option(StreamInput in) throws IOException {
super(in); super(in);
this.doc = Lucene.readScoreDoc(in); this.doc = Lucene.readScoreDoc(in);
@ -455,5 +438,4 @@ public final class CompletionSuggestion extends Suggest.Suggestion<CompletionSug
} }
} }
} }
} }

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ContextParser;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.Suggest;
@ -44,8 +43,6 @@ public class PhraseSuggestion extends Suggest.Suggestion<PhraseSuggestion.Entry>
@Deprecated @Deprecated
public static final int TYPE = 3; public static final int TYPE = 3;
public PhraseSuggestion() {}
public PhraseSuggestion(String name, int size) { public PhraseSuggestion(String name, int size) {
super(name, size); super(name, size);
} }
@ -64,11 +61,6 @@ public class PhraseSuggestion extends Suggest.Suggestion<PhraseSuggestion.Entry>
return TYPE; return TYPE;
} }
@Override
protected Entry newEntry() {
return new Entry();
}
@Override @Override
protected Entry newEntry(StreamInput in) throws IOException { protected Entry newEntry(StreamInput in) throws IOException {
return new Entry(in); return new Entry(in);
@ -132,19 +124,13 @@ public class PhraseSuggestion extends Suggest.Suggestion<PhraseSuggestion.Entry>
static { static {
declareCommonFields(PARSER); declareCommonFields(PARSER);
PARSER.declareObjectArray(Entry::addOptions, (ContextParser<Void, Option>) (p, c) -> Option.fromXContent(p), PARSER.declareObjectArray(Entry::addOptions, (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS));
new ParseField(OPTIONS));
} }
public static Entry fromXContent(XContentParser parser) { public static Entry fromXContent(XContentParser parser) {
return PARSER.apply(parser, null); return PARSER.apply(parser, null);
} }
@Override
protected Option newOption() {
return new Option();
}
@Override @Override
protected Option newOption(StreamInput in) throws IOException { protected Option newOption(StreamInput in) throws IOException {
return new Option(in); return new Option(in);
@ -169,10 +155,6 @@ public class PhraseSuggestion extends Suggest.Suggestion<PhraseSuggestion.Entry>
public static class Option extends Suggestion.Entry.Option { public static class Option extends Suggestion.Entry.Option {
public Option() {
super();
}
public Option(Text text, Text highlighted, float score, Boolean collateMatch) { public Option(Text text, Text highlighted, float score, Boolean collateMatch) {
super(text, highlighted, score, collateMatch); super(text, highlighted, score, collateMatch);
} }

View File

@ -52,8 +52,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
private SortBy sort; private SortBy sort;
public TermSuggestion() {}
public TermSuggestion(String name, int size, SortBy sort) { public TermSuggestion(String name, int size, SortBy sort) {
super(name, size); super(name, size);
this.sort = sort; this.sort = sort;
@ -61,7 +59,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
public TermSuggestion(StreamInput in) throws IOException { public TermSuggestion(StreamInput in) throws IOException {
super(in); super(in);
if (in.getVersion().onOrAfter(Version.V_7_0_0)) { if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
sort = SortBy.readFromStream(in); sort = SortBy.readFromStream(in);
} }
@ -80,7 +77,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
} }
return FREQUENCY.compare(first, second); return FREQUENCY.compare(first, second);
} }
} }
// Same behaviour as comparators in suggest module, but for SuggestedWord // Same behaviour as comparators in suggest module, but for SuggestedWord
@ -105,7 +101,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
// third criteria: term text // third criteria: term text
return first.getText().compareTo(second.getText()); return first.getText().compareTo(second.getText());
} }
} }
@Override @Override
@ -154,11 +149,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
return suggestion; return suggestion;
} }
@Override
protected Entry newEntry() {
return new Entry();
}
@Override @Override
protected Entry newEntry(StreamInput in) throws IOException { protected Entry newEntry(StreamInput in) throws IOException {
return new Entry(in); return new Entry(in);
@ -184,17 +174,12 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
super(text, offset, length); super(text, offset, length);
} }
public Entry() {} private Entry() {}
public Entry(StreamInput in) throws IOException { public Entry(StreamInput in) throws IOException {
super(in); super(in);
} }
@Override
protected Option newOption() {
return new Option();
}
@Override @Override
protected Option newOption(StreamInput in) throws IOException { protected Option newOption(StreamInput in) throws IOException {
return new Option(in); return new Option(in);
@ -236,10 +221,6 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
freq += ((Option) otherOption).freq; freq += ((Option) otherOption).freq;
} }
protected Option() {
super();
}
public void setFreq(int freq) { public void setFreq(int freq) {
this.freq = freq; this.freq = freq;
} }
@ -283,6 +264,5 @@ public class TermSuggestion extends Suggestion<TermSuggestion.Entry> {
return PARSER.apply(parser, null); return PARSER.apply(parser, null);
} }
} }
} }
} }

View File

@ -44,11 +44,11 @@ import org.elasticsearch.search.aggregations.bucket.significant.heuristics.Signi
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder;
import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.InternalDerivative; import org.elasticsearch.search.aggregations.pipeline.InternalDerivative;
import org.elasticsearch.search.aggregations.pipeline.MovAvgModel; import org.elasticsearch.search.aggregations.pipeline.MovAvgModel;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.SimpleModel; import org.elasticsearch.search.aggregations.pipeline.SimpleModel;
import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
@ -579,11 +579,6 @@ public class SearchModuleTests extends ESTestCase {
super(in); super(in);
} }
@Override
protected Entry newEntry() {
return null;
}
@Override @Override
protected Entry newEntry(StreamInput in) throws IOException { protected Entry newEntry(StreamInput in) throws IOException {
return null; return null;