Skip to content

Commit

Permalink
Addressed more comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed May 7, 2015
1 parent 3af4c67 commit d49a4d8
Show file tree
Hide file tree
Showing 34 changed files with 267 additions and 185 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AndQueryBuilder extends BaseQueryBuilder {

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

private String filterName;
private String queryName;

public AndQueryBuilder(QueryBuilder... filters) {
for (QueryBuilder filter : filters) {
Expand All @@ -53,8 +53,8 @@ public AndQueryBuilder add(QueryBuilder filterBuilder) {
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public AndQueryBuilder filterName(String filterName) {
this.filterName = filterName;
public AndQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

Expand All @@ -66,8 +66,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
filter.toXContent(builder, params);
}
builder.endArray();
if (filterName != null) {
builder.field("_name", filterName);
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/elasticsearch/index/query/AndQueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
ArrayList<Query> queries = newArrayList();
boolean queriesFound = false;

String filterName = null;
String queryName = null;
String currentFieldName = null;
XContentParser.Token token = parser.currentToken();
if (token == XContentParser.Token.START_ARRAY) {
Expand Down Expand Up @@ -91,16 +91,16 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
}
} else if (token.isValue()) {
if ("_name".equals(currentFieldName)) {
filterName = parser.text();
queryName = parser.text();
} else {
throw new QueryParsingException(parseContext, "[and] filter does not support [" + currentFieldName + "]");
throw new QueryParsingException(parseContext, "[and] query does not support [" + currentFieldName + "]");
}
}
}
}

if (!queriesFound) {
throw new QueryParsingException(parseContext, "[and] filter requires 'filters' to be set on it'");
throw new QueryParsingException(parseContext, "[and] query requires 'filters' to be set on it'");
}

if (queries.isEmpty()) {
Expand All @@ -112,8 +112,8 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
for (Query f : queries) {
query.add(f, Occur.MUST);
}
if (filterName != null) {
parseContext.addNamedQuery(filterName, query);
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public ExistsQueryBuilder(String name) {
/**
* Sets the query name for the query that can be used when searching for matched_queries per hit.
*/
public ExistsQueryBuilder queryName(String filterName) {
this.queryName = filterName;
public ExistsQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
XContentParser parser = parseContext.parser();

String fieldPattern = null;
String filterName = null;
String queryName = null;

XContentParser.Token token;
String currentFieldName = null;
Expand All @@ -66,7 +66,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
if ("field".equals(currentFieldName)) {
fieldPattern = parser.text();
} else if ("_name".equals(currentFieldName)) {
filterName = parser.text();
queryName = parser.text();
} else {
throw new QueryParsingException(parseContext, "[exists] query does not support [" + currentFieldName + "]");
}
Expand All @@ -77,10 +77,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
throw new QueryParsingException(parseContext, "exists must be provided with a [field]");
}

return newFilter(parseContext, fieldPattern, filterName);
return newFilter(parseContext, fieldPattern, queryName);
}

public static Query newFilter(QueryParseContext parseContext, String fieldPattern, String filterName) {
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, String queryName) {
final FieldMappers fieldNamesMappers = parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
final FieldNamesFieldMapper fieldNamesMapper = (FieldNamesFieldMapper)fieldNamesMappers.mapper();

Expand Down Expand Up @@ -119,8 +119,8 @@ public static Query newFilter(QueryParseContext parseContext, String fieldPatter
boolFilter.add(filter, BooleanClause.Occur.SHOULD);
}

if (filterName != null) {
parseContext.addNamedQuery(filterName, boolFilter);
if (queryName != null) {
parseContext.addNamedQuery(queryName, boolFilter);
}
return new ConstantScoreQuery(boolFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
* The "fquery" filter is the same as the {@link QueryFilterParser} except that it allows also to
* associate a name with the query filter.
*/
public class FQueryQueryParser implements QueryParser {
@Deprecated
public class FQueryFilterParser implements QueryParser {

public static final String NAME = "fquery";

@Inject
public FQueryQueryParser() {
public FQueryFilterParser() {
}

@Override
Expand All @@ -50,7 +51,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
Query query = null;
boolean queryFound = false;

String filterName = null;
String queryName = null;
String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand All @@ -63,13 +64,13 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
queryFound = true;
query = parseContext.parseInnerQuery();
} else {
throw new QueryParsingException(parseContext, "[fquery] filter does not support [" + currentFieldName + "]");
throw new QueryParsingException(parseContext, "[fquery] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if ("_name".equals(currentFieldName)) {
filterName = parser.text();
queryName = parser.text();
} else {
throw new QueryParsingException(parseContext, "[fquery] filter does not support [" + currentFieldName + "]");
throw new QueryParsingException(parseContext, "[fquery] query does not support [" + currentFieldName + "]");
}
}
}
Expand All @@ -80,8 +81,8 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
return null;
}
query = new ConstantScoreQuery(query);
if (filterName != null) {
parseContext.addNamedQuery(filterName, query);
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GeoBoundingBoxQueryBuilder extends BaseQueryBuilder {

private double[] box = {Double.NaN, Double.NaN, Double.NaN, Double.NaN};

private String filterName;
private String queryName;
private String type;

public GeoBoundingBoxQueryBuilder(String name) {
Expand Down Expand Up @@ -132,8 +132,8 @@ public GeoBoundingBoxQueryBuilder topRight(String geohash) {
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public GeoBoundingBoxQueryBuilder queryName(String filterName) {
this.filterName = filterName;
public GeoBoundingBoxQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

Expand Down Expand Up @@ -166,8 +166,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.array(BOTTOM_RIGHT, box[RIGHT], box[BOTTOM]);
builder.endObject();

if (filterName != null) {
builder.field("_name", filterName);
if (queryName != null) {
builder.field("_name", queryName);
}
if (type != null) {
builder.field("type", type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
double left = Double.NaN;
double right = Double.NaN;

String filterName = null;
String queryName = null;
String currentFieldName = null;
XContentParser.Token token;
boolean normalize = true;
Expand Down Expand Up @@ -135,13 +135,13 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
}
} else if (token.isValue()) {
if ("_name".equals(currentFieldName)) {
filterName = parser.text();
queryName = parser.text();
} else if ("normalize".equals(currentFieldName)) {
normalize = parser.booleanValue();
} else if ("type".equals(currentFieldName)) {
type = parser.text();
} else {
throw new QueryParsingException(parseContext, "[geo_bbox] filter does not support [" + currentFieldName + "]");
throw new QueryParsingException(parseContext, "[geo_bbox] query does not support [" + currentFieldName + "]");
}
}
}
Expand Down Expand Up @@ -182,8 +182,8 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
+ "] not supported, either 'indexed' or 'memory' are allowed");
}

if (filterName != null) {
parseContext.addNamedQuery(filterName, filter);
if (queryName != null) {
parseContext.addNamedQuery(queryName, filter);
}
return filter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GeoDistanceQueryBuilder extends BaseQueryBuilder {

private String optimizeBbox;

private String filterName;
private String queryName;

public GeoDistanceQueryBuilder(String name) {
this.name = name;
Expand Down Expand Up @@ -95,8 +95,8 @@ public GeoDistanceQueryBuilder optimizeBbox(String optimizeBbox) {
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public GeoDistanceQueryBuilder queryName(String filterName) {
this.filterName = filterName;
public GeoDistanceQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

Expand All @@ -115,8 +115,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (optimizeBbox != null) {
builder.field("optimize_bbox", optimizeBbox);
}
if (filterName != null) {
builder.field("_name", filterName);
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.query;

import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
Expand Down Expand Up @@ -57,12 +57,12 @@ public String[] names() {
}

@Override
public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
XContentParser parser = parseContext.parser();

XContentParser.Token token;

String filterName = null;
String queryName = null;
String currentFieldName = null;
GeoPoint point = new GeoPoint();
String fieldName = null;
Expand Down Expand Up @@ -96,7 +96,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
GeoHashUtils.decode(parser.text(), point);
} else {
throw new QueryParsingException(parseContext, "[geo_distance] filter does not support [" + currentFieldName
throw new QueryParsingException(parseContext, "[geo_distance] query does not support [" + currentFieldName
+ "]");
}
}
Expand All @@ -122,7 +122,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
GeoHashUtils.decode(parser.text(), point);
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
} else if ("_name".equals(currentFieldName)) {
filterName = parser.text();
queryName = parser.text();
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
optimizeBbox = parser.textOrNull();
} else if ("normalize".equals(currentFieldName)) {
Expand Down Expand Up @@ -160,10 +160,10 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar


IndexGeoPointFieldData indexFieldData = parseContext.getForField(mapper);
Filter filter = new GeoDistanceFilter(point.lat(), point.lon(), distance, geoDistance, indexFieldData, geoMapper, optimizeBbox);
if (filterName != null) {
parseContext.addNamedQuery(filterName, filter);
Query query = new GeoDistanceFilter(point.lat(), point.lon(), distance, geoDistance, indexFieldData, geoMapper, optimizeBbox);
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return filter;
return query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GeoDistanceRangeQueryBuilder extends BaseQueryBuilder {

private GeoDistance geoDistance;

private String filterName;
private String queryName;

private String optimizeBbox;

Expand Down Expand Up @@ -131,8 +131,8 @@ public GeoDistanceRangeQueryBuilder optimizeBbox(String optimizeBbox) {
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public GeoDistanceRangeQueryBuilder queryName(String filterName) {
this.filterName = filterName;
public GeoDistanceRangeQueryBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

Expand All @@ -154,8 +154,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (optimizeBbox != null) {
builder.field("optimize_bbox", optimizeBbox);
}
if (filterName != null) {
builder.field("_name", filterName);
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
}
Expand Down
Loading

0 comments on commit d49a4d8

Please sign in to comment.