Skip to content

Commit 494a468

Browse files
committed
rebased + addressed comments
1 parent 943c827 commit 494a468

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ public Query toQuery(QueryParseContext parseContext) throws QueryParsingExceptio
283283
}
284284
}
285285

286-
Occur highFreqOccur = highFreqOperator.toMustOrShouldClause();
287-
Occur lowFreqOccur = lowFreqOperator.toMustOrShouldClause();
286+
Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur();
287+
Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur();
288288

289289
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency, disableCoord, mapper);
290290
commonsQuery.setBoost(boost);
@@ -334,8 +334,8 @@ public QueryValidationException validate() {
334334
@Override
335335
public CommonTermsQueryBuilder readFrom(StreamInput in) throws IOException {
336336
CommonTermsQueryBuilder commonTermsQueryBuilder = new CommonTermsQueryBuilder(in.readString(), in.readGenericValue());
337-
commonTermsQueryBuilder.highFreqOperator = Operator.readFrom(in);
338-
commonTermsQueryBuilder.lowFreqOperator = Operator.readFrom(in);
337+
commonTermsQueryBuilder.highFreqOperator = Operator.PROTOTYPE.readFrom(in);
338+
commonTermsQueryBuilder.lowFreqOperator = Operator.PROTOTYPE.readFrom(in);
339339
commonTermsQueryBuilder.analyzer = in.readOptionalString();
340340
commonTermsQueryBuilder.boost = in.readFloat();
341341
commonTermsQueryBuilder.lowFreqMinimumShouldMatch = in.readOptionalString();

core/src/main/java/org/elasticsearch/index/query/QueryBuilder.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,26 @@
2828
import org.elasticsearch.common.io.stream.NamedWriteable;
2929
import org.elasticsearch.common.io.stream.StreamInput;
3030
import org.elasticsearch.common.io.stream.StreamOutput;
31+
import org.elasticsearch.common.io.stream.Writeable;
3132
import org.elasticsearch.common.xcontent.ToXContent;
3233
import org.elasticsearch.common.xcontent.XContentType;
3334

3435
import java.io.IOException;
3536

3637
public interface QueryBuilder<QB extends QueryBuilder> extends NamedWriteable<QB>, ToXContent {
3738

38-
public static enum Operator {
39+
public static enum Operator implements Writeable {
3940
OR(0), AND(1);
4041

4142
private final int ordinal;
42-
43+
44+
static final Operator PROTOTYPE = OR;
45+
4346
private Operator(int ordinal) {
4447
this.ordinal = ordinal;
4548
}
4649

47-
public BooleanClause.Occur toMustOrShouldClause() {
50+
public BooleanClause.Occur toBooleanClauseOccur() {
4851
switch (this) {
4952
case OR:
5053
return BooleanClause.Occur.SHOULD;
@@ -55,7 +58,7 @@ public BooleanClause.Occur toMustOrShouldClause() {
5558
}
5659
}
5760

58-
public static Operator readFrom(StreamInput in) throws IOException {
61+
public Operator readFrom(StreamInput in) throws IOException {
5962
int ord = in.readVInt();
6063
for (Operator operator : Operator.values()) {
6164
if (operator.ordinal == ord) {

core/src/test/java/org/elasticsearch/index/query/CommonTermsQueryBuilderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
2424
import org.apache.lucene.search.BooleanClause.Occur;
2525
import org.apache.lucene.search.Query;
26-
import org.elasticsearch.index.mapper.FieldMapper;
2726
import org.elasticsearch.index.mapper.MappedFieldType;
2827
import org.elasticsearch.index.query.QueryBuilder.Operator;
2928
import org.junit.Test;
@@ -104,8 +103,8 @@ protected Query createExpectedQuery(CommonTermsQueryBuilder queryBuilder, QueryP
104103
analyzer = context.analysisService().analyzer(queryBuilder.analyzer());
105104
}
106105

107-
Occur highFreqOccur = queryBuilder.highFreqOperator().toMustOrShouldClause();
108-
Occur lowFreqOccur = queryBuilder.lowFreqOperator().toMustOrShouldClause();
106+
Occur highFreqOccur = queryBuilder.highFreqOperator().toBooleanClauseOccur();
107+
Occur lowFreqOccur = queryBuilder.lowFreqOperator().toBooleanClauseOccur();
109108

110109
ExtendedCommonTermsQuery expectedQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, queryBuilder.cutoffFrequency(),
111110
queryBuilder.disableCoord(), mapper);

0 commit comments

Comments
 (0)