Skip to content

Commit

Permalink
Merge pull request #11178 from cbuescher/feature/query-refactoring-mo…
Browse files Browse the repository at this point in the history
…vename

Query Refactoring: Moving parser NAME constant to corresponding query builder
  • Loading branch information
cbuescher committed May 22, 2015
2 parents ca70297 + 283fe90 commit 1c60436
Show file tree
Hide file tree
Showing 110 changed files with 418 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.index.query;

import com.google.common.collect.Lists;

import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand All @@ -32,6 +33,8 @@
@Deprecated
public class AndQueryBuilder extends QueryBuilder {

public static final String NAME = "and";

private ArrayList<QueryBuilder> filters = Lists.newArrayList();

private String queryName;
Expand Down Expand Up @@ -60,7 +63,7 @@ public AndQueryBuilder queryName(String queryName) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(AndQueryParser.NAME);
builder.startObject(NAME);
builder.startArray("filters");
for (QueryBuilder filter : filters) {
filter.toXContent(builder, params);
Expand All @@ -73,7 +76,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected String parserName() {
return AndQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
@Deprecated
public class AndQueryParser extends BaseQueryParserTemp {

public static final String NAME = "and";

@Inject
public AndQueryParser() {
}

@Override
public String[] names() {
return new String[]{NAME};
return new String[]{AndQueryBuilder.NAME};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Objects;

public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends QueryBuilder<QB> implements BoostableQueryBuilder<QB> {

/** Name of field to match against. */
protected final String fieldName;

Expand Down Expand Up @@ -158,7 +158,7 @@ public QB boost(float boost) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(parserName());
builder.startObject(queryId());
if (boost == 1.0f && queryName == null) {
builder.field(fieldName, convertToStringIfBytesRef(this.value));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public class BoolQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<BoolQueryBuilder> {

public static final String NAME = "bool";

private final List<QueryBuilder> mustClauses = new ArrayList<>();

private final List<QueryBuilder> mustNotClauses = new ArrayList<>();
Expand Down Expand Up @@ -160,7 +162,7 @@ public BoolQueryBuilder queryName(String queryName) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("bool");
builder.startObject(NAME);
doXArrayContent("must", mustClauses, builder, params);
doXArrayContent("filter", filterClauses, builder, params);
doXArrayContent("must_not", mustNotClauses, builder, params);
Expand Down Expand Up @@ -200,7 +202,7 @@ private void doXArrayContent(String field, List<QueryBuilder> clauses, XContentB
}

@Override
protected String parserName() {
return BoolQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@
*/
public class BoolQueryParser extends BaseQueryParserTemp {

public static final String NAME = "bool";

@Inject
public BoolQueryParser(Settings settings) {
BooleanQuery.setMaxClauseCount(settings.getAsInt("index.query.bool.max_clause_count", settings.getAsInt("indices.query.bool.max_clause_count", BooleanQuery.getMaxClauseCount())));
}

@Override
public String[] names() {
return new String[]{NAME};
return new String[]{BoolQueryBuilder.NAME};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/
public class BoostingQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<BoostingQueryBuilder> {

public static final String NAME = "boosting";

private QueryBuilder positiveQuery;

private QueryBuilder negativeQuery;
Expand Down Expand Up @@ -81,7 +83,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (negativeBoost == -1) {
throw new IllegalArgumentException("boosting query requires negativeBoost to be set");
}
builder.startObject(BoostingQueryParser.NAME);
builder.startObject(NAME);
builder.field("positive");
positiveQuery.toXContent(builder, params);
builder.field("negative");
Expand All @@ -96,7 +98,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected String parserName() {
return BoostingQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
*/
public class BoostingQueryParser extends BaseQueryParserTemp {

public static final String NAME = "boosting";

@Inject
public BoostingQueryParser() {
}

@Override
public String[] names() {
return new String[]{NAME};
return new String[]{BoostingQueryBuilder.NAME};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
*/
public class CommonTermsQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<CommonTermsQueryBuilder> {

public static final String NAME = "common";

public static enum Operator {
OR, AND
}
Expand Down Expand Up @@ -161,7 +163,7 @@ public CommonTermsQueryBuilder queryName(String queryName) {

@Override
public void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(CommonTermsQueryParser.NAME);
builder.startObject(NAME);
builder.startObject(name);

builder.field("query", text);
Expand Down Expand Up @@ -202,7 +204,7 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
}

@Override
protected String parserName() {
return CommonTermsQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
*/
public class CommonTermsQueryParser extends BaseQueryParserTemp {

public static final String NAME = "common";

static final float DEFAULT_MAX_TERM_DOC_FREQ = 0.01f;

static final Occur DEFAULT_HIGH_FREQ_OCCUR = Occur.SHOULD;
Expand All @@ -56,7 +54,7 @@ public CommonTermsQueryParser() {

@Override
public String[] names() {
return new String[] { NAME };
return new String[] { CommonTermsQueryBuilder.NAME };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public class ConstantScoreQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<ConstantScoreQueryBuilder> {

public static final String NAME = "constant_score";

private final QueryBuilder filterBuilder;

private float boost = -1;
Expand All @@ -57,7 +59,7 @@ public ConstantScoreQueryBuilder boost(float boost) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(ConstantScoreQueryParser.NAME);
builder.startObject(NAME);
builder.field("filter");
filterBuilder.toXContent(builder, params);

Expand All @@ -68,7 +70,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected String parserName() {
return ConstantScoreQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/
public class ConstantScoreQueryParser extends BaseQueryParserTemp {

public static final String NAME = "constant_score";
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");

@Inject
Expand All @@ -42,7 +41,7 @@ public ConstantScoreQueryParser() {

@Override
public String[] names() {
return new String[]{NAME, Strings.toCamelCase(NAME)};
return new String[]{ConstantScoreQueryBuilder.NAME, Strings.toCamelCase(ConstantScoreQueryBuilder.NAME)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.query;

import org.apache.lucene.search.Query;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand All @@ -34,6 +33,8 @@
*/
public class DisMaxQueryBuilder extends QueryBuilder implements BoostableQueryBuilder<DisMaxQueryBuilder> {

public static final String NAME = "dis_max";

private ArrayList<QueryBuilder> queries = newArrayList();

private float boost = -1;
Expand Down Expand Up @@ -81,7 +82,7 @@ public DisMaxQueryBuilder queryName(String queryName) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(DisMaxQueryParser.NAME);
builder.startObject(NAME);
if (tieBreaker != -1) {
builder.field("tie_breaker", tieBreaker);
}
Expand All @@ -100,7 +101,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected String parserName() {
return DisMaxQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
*/
public class DisMaxQueryParser extends BaseQueryParserTemp {

public static final String NAME = "dis_max";

@Inject
public DisMaxQueryParser() {
}

@Override
public String[] names() {
return new String[]{NAME, Strings.toCamelCase(NAME)};
return new String[]{DisMaxQueryBuilder.NAME, Strings.toCamelCase(DisMaxQueryBuilder.NAME)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
public class ExistsQueryBuilder extends QueryBuilder {

public static final String NAME = "exists";

private String name;

private String queryName;
Expand All @@ -46,7 +48,7 @@ public ExistsQueryBuilder queryName(String queryName) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(ExistsQueryParser.NAME);
builder.startObject(NAME);
builder.field("field", name);
if (queryName != null) {
builder.field("_name", queryName);
Expand All @@ -55,7 +57,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected String parserName() {
return ExistsQueryParser.NAME;
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
*/
public class ExistsQueryParser extends BaseQueryParserTemp {

public static final String NAME = "exists";

@Inject
public ExistsQueryParser() {
}

@Override
public String[] names() {
return new String[]{NAME};
return new String[]{ExistsQueryBuilder.NAME};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
@Deprecated
public class FQueryFilterParser extends BaseQueryParserTemp {

public static final String NAME = "fquery";

@Inject
public FQueryFilterParser() {
}

@Override
public String[] names() {
return new String[]{NAME};
return new String[]{QueryFilterBuilder.FQUERY_NAME};
}

@Override
Expand Down
Loading

0 comments on commit 1c60436

Please sign in to comment.