Migrate more functions to (read|write)NamedWriteable

ScoreFunction and Suggestion.
Relates #17682.
This commit is contained in:
Nik Everett 2016-04-18 21:07:46 -04:00
parent ba08313417
commit 339d927ee4
5 changed files with 8 additions and 50 deletions

View File

@ -35,9 +35,6 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
import org.elasticsearch.search.suggest.SuggestionBuilder;
import org.elasticsearch.search.suggest.phrase.SmoothingModel;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
@ -741,24 +738,6 @@ public abstract class StreamInput extends InputStream {
return readNamedWriteable(QueryBuilder.class); return readNamedWriteable(QueryBuilder.class);
} }
/**
* Reads a {@link SuggestionBuilder} from the current stream
* @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link SuggestionBuilder}.
*/
@Deprecated
public SuggestionBuilder<?> readSuggestion() throws IOException {
return readNamedWriteable(SuggestionBuilder.class);
}
/**
* Reads a {@link org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder} from the current stream
* @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link ScoreFunctionBuilder}.
*/
@Deprecated
public ScoreFunctionBuilder<?> readScoreFunction() throws IOException {
return readNamedWriteable(ScoreFunctionBuilder.class);
}
/** /**
* Reads a list of objects * Reads a list of objects
*/ */

View File

@ -34,9 +34,6 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
import org.elasticsearch.search.suggest.SuggestionBuilder;
import org.elasticsearch.search.suggest.phrase.SmoothingModel;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.joda.time.ReadableInstant; import org.joda.time.ReadableInstant;
@ -705,15 +702,6 @@ public abstract class StreamOutput extends OutputStream {
writeNamedWriteable(queryBuilder); writeNamedWriteable(queryBuilder);
} }
/**
* Writes a {@link ScoreFunctionBuilder} to the current stream
* @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
*/
@Deprecated
public void writeScoreFunction(ScoreFunctionBuilder<?> scoreFunctionBuilder) throws IOException {
writeNamedWriteable(scoreFunctionBuilder);
}
/** /**
* Writes the given {@link GeoPoint} to the stream * Writes the given {@link GeoPoint} to the stream
*/ */
@ -750,13 +738,4 @@ public abstract class StreamOutput extends OutputStream {
obj.writeTo(this); obj.writeTo(this);
} }
} }
/**
* Writes a {@link SuggestionBuilder} to the current stream
* @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
*/
@Deprecated
public void writeSuggestion(SuggestionBuilder<?> suggestion) throws IOException {
writeNamedWriteable(suggestion);
}
} }

View File

@ -354,14 +354,14 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScor
* Read from a stream. * Read from a stream.
*/ */
public FilterFunctionBuilder(StreamInput in) throws IOException { public FilterFunctionBuilder(StreamInput in) throws IOException {
filter = in.readQuery(); filter = in.readNamedWriteable(QueryBuilder.class);
scoreFunction = in.readScoreFunction(); scoreFunction = in.readNamedWriteable(ScoreFunctionBuilder.class);
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeQuery(filter); out.writeNamedWriteable(filter);
out.writeScoreFunction(scoreFunction); out.writeNamedWriteable(scoreFunction);
} }
public QueryBuilder<?> getFilter() { public QueryBuilder<?> getFilter() {

View File

@ -65,7 +65,7 @@ public class SuggestBuilder extends ToXContentToBytes implements Writeable<Sugge
globalText = in.readOptionalString(); globalText = in.readOptionalString();
final int size = in.readVInt(); final int size = in.readVInt();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
suggestions.put(in.readString(), in.readSuggestion()); suggestions.put(in.readString(), in.readNamedWriteable(SuggestionBuilder.class));
} }
} }
@ -76,7 +76,7 @@ public class SuggestBuilder extends ToXContentToBytes implements Writeable<Sugge
out.writeVInt(size); out.writeVInt(size);
for (Entry<String, SuggestionBuilder<?>> suggestion : suggestions.entrySet()) { for (Entry<String, SuggestionBuilder<?>> suggestion : suggestions.entrySet()) {
out.writeString(suggestion.getKey()); out.writeString(suggestion.getKey());
out.writeSuggestion(suggestion.getValue()); out.writeNamedWriteable(suggestion.getValue());
} }
} }

View File

@ -217,9 +217,9 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected SB serializedCopy(SB original) throws IOException { protected SB serializedCopy(SB original) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) { try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeSuggestion(original); output.writeNamedWriteable(original);
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) { try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
return (SB) in.readSuggestion(); return (SB) in.readNamedWriteable(SuggestionBuilder.class);
} }
} }
} }