Merge pull request #11344 from cbuescher/feature/query-refactoring-linkParsers

Query Refactoring: Adding getBuilderPrototype() method to all QueryParsers
This commit is contained in:
Christoph Büscher 2015-05-26 16:03:45 +02:00
commit dd5ecfc943
106 changed files with 407 additions and 10 deletions

View File

@ -39,6 +39,8 @@ public class AndQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final AndQueryBuilder PROTOTYPE = new AndQueryBuilder();
public AndQueryBuilder(QueryBuilder... filters) { public AndQueryBuilder(QueryBuilder... filters) {
for (QueryBuilder filter : filters) { for (QueryBuilder filter : filters) {
this.filters.add(filter); this.filters.add(filter);

View File

@ -115,4 +115,9 @@ public class AndQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public AndQueryBuilder getBuilderPrototype() {
return AndQueryBuilder.PROTOTYPE;
}
} }

View File

@ -51,6 +51,8 @@ public class BoolQueryBuilder extends QueryBuilder implements BoostableQueryBuil
private String queryName; private String queryName;
static final BoolQueryBuilder PROTOTYPE = new BoolQueryBuilder();
/** /**
* Adds a query that <b>must</b> appear in the matching documents and will * Adds a query that <b>must</b> appear in the matching documents and will
* contribute to scoring. * contribute to scoring.

View File

@ -171,4 +171,9 @@ public class BoolQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public BoolQueryBuilder getBuilderPrototype() {
return BoolQueryBuilder.PROTOTYPE;
}
} }

View File

@ -47,8 +47,9 @@ public class BoostingQueryBuilder extends QueryBuilder implements BoostableQuery
private float boost = -1; private float boost = -1;
public BoostingQueryBuilder() { static final BoostingQueryBuilder PROTOTYPE = new BoostingQueryBuilder();
public BoostingQueryBuilder() {
} }
public BoostingQueryBuilder positive(QueryBuilder positiveQuery) { public BoostingQueryBuilder positive(QueryBuilder positiveQuery) {

View File

@ -98,4 +98,9 @@ public class BoostingQueryParser extends BaseQueryParserTemp {
} }
return boostingQuery; return boostingQuery;
} }
@Override
public BoostingQueryBuilder getBuilderPrototype() {
return BoostingQueryBuilder.PROTOTYPE;
}
} }

View File

@ -72,6 +72,8 @@ public class CommonTermsQueryBuilder extends QueryBuilder implements BoostableQu
private String queryName; private String queryName;
static final CommonTermsQueryBuilder PROTOTYPE = new CommonTermsQueryBuilder();
/** /**
* Constructs a new common terms query. * Constructs a new common terms query.
*/ */
@ -86,6 +88,14 @@ public class CommonTermsQueryBuilder extends QueryBuilder implements BoostableQu
this.name = name; this.name = name;
} }
/**
* private constructor used onyl internally
*/
private CommonTermsQueryBuilder() {
this.text = null;
this.name = null;
}
/** /**
* Sets the operator to use for terms with a high document frequency * Sets the operator to use for terms with a high document frequency
* (greater than or equal to {@link #cutoffFrequency(float)}. Defaults to * (greater than or equal to {@link #cutoffFrequency(float)}. Defaults to

View File

@ -219,4 +219,9 @@ public class CommonTermsQueryParser extends BaseQueryParserTemp {
query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch); query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch);
return query; return query;
} }
@Override
public CommonTermsQueryBuilder getBuilderPrototype() {
return CommonTermsQueryBuilder.PROTOTYPE;
}
} }

View File

@ -37,6 +37,8 @@ public class ConstantScoreQueryBuilder extends QueryBuilder implements Boostable
private float boost = -1; private float boost = -1;
static final ConstantScoreQueryBuilder PROTOTYPE = new ConstantScoreQueryBuilder();
/** /**
* A query that wraps a query and simply returns a constant score equal to the * A query that wraps a query and simply returns a constant score equal to the
* query boost for every document in the query. * query boost for every document in the query.
@ -47,6 +49,13 @@ public class ConstantScoreQueryBuilder extends QueryBuilder implements Boostable
this.filterBuilder = Objects.requireNonNull(filterBuilder); this.filterBuilder = Objects.requireNonNull(filterBuilder);
} }
/**
* private constructor only used for serialization
*/
private ConstantScoreQueryBuilder() {
this.filterBuilder = null;
}
/** /**
* Sets the boost for this query. Documents matching this query will (in addition to the normal * Sets the boost for this query. Documents matching this query will (in addition to the normal
* weightings) have their score multiplied by the boost provided. * weightings) have their score multiplied by the boost provided.

View File

@ -86,4 +86,9 @@ public class ConstantScoreQueryParser extends BaseQueryParserTemp {
filter.setBoost(boost); filter.setBoost(boost);
return filter; return filter;
} }
@Override
public ConstantScoreQueryBuilder getBuilderPrototype() {
return ConstantScoreQueryBuilder.PROTOTYPE;
}
} }

View File

@ -43,6 +43,8 @@ public class DisMaxQueryBuilder extends QueryBuilder implements BoostableQueryBu
private String queryName; private String queryName;
static final DisMaxQueryBuilder PROTOTYPE = new DisMaxQueryBuilder();
/** /**
* Add a sub-query to this disjunction. * Add a sub-query to this disjunction.
*/ */

View File

@ -111,4 +111,9 @@ public class DisMaxQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public DisMaxQueryBuilder getBuilderPrototype() {
return DisMaxQueryBuilder.PROTOTYPE;
}
} }

View File

@ -34,6 +34,8 @@ public class ExistsQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder(null);
public ExistsQueryBuilder(String name) { public ExistsQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -122,4 +122,9 @@ public class ExistsQueryParser extends BaseQueryParserTemp {
return new ConstantScoreQuery(boolFilter); return new ConstantScoreQuery(boolFilter);
} }
@Override
public ExistsQueryBuilder getBuilderPrototype() {
return ExistsQueryBuilder.PROTOTYPE;
}
} }

View File

@ -84,4 +84,9 @@ public class FQueryFilterParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public QueryFilterBuilder getBuilderPrototype() {
return QueryFilterBuilder.PROTOTYPE;
}
} }

View File

@ -35,6 +35,8 @@ public class FieldMaskingSpanQueryBuilder extends QueryBuilder implements SpanQu
private String queryName; private String queryName;
static final FieldMaskingSpanQueryBuilder PROTOTYPE = new FieldMaskingSpanQueryBuilder(null, null);
public FieldMaskingSpanQueryBuilder(SpanQueryBuilder queryBuilder, String field) { public FieldMaskingSpanQueryBuilder(SpanQueryBuilder queryBuilder, String field) {
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;
this.field = field; this.field = field;

View File

@ -100,4 +100,9 @@ public class FieldMaskingSpanQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public FieldMaskingSpanQueryBuilder getBuilderPrototype() {
return FieldMaskingSpanQueryBuilder.PROTOTYPE;
}
} }

View File

@ -41,6 +41,8 @@ public class FilteredQueryBuilder extends QueryBuilder implements BoostableQuery
private String queryName; private String queryName;
static final FilteredQueryBuilder PROTOTYPE = new FilteredQueryBuilder(null, null);
/** /**
* A query that applies a filter to the results of another query. * A query that applies a filter to the results of another query.
* *

View File

@ -118,4 +118,9 @@ public class FilteredQueryParser extends BaseQueryParserTemp {
} }
return filteredQuery; return filteredQuery;
} }
@Override
public FilteredQueryBuilder getBuilderPrototype() {
return FilteredQueryBuilder.PROTOTYPE;
}
} }

View File

@ -50,6 +50,8 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
private String queryName; private String queryName;
static final FuzzyQueryBuilder PROTOTYPE = new FuzzyQueryBuilder(null, null);
/** /**
* Constructs a new term query. * Constructs a new term query.
* *

View File

@ -130,4 +130,9 @@ public class FuzzyQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public FuzzyQueryBuilder getBuilderPrototype() {
return FuzzyQueryBuilder.PROTOTYPE;
}
} }

View File

@ -44,6 +44,8 @@ public class GeoBoundingBoxQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
private String type; private String type;
static final GeoBoundingBoxQueryBuilder PROTOTYPE = new GeoBoundingBoxQueryBuilder(null);
public GeoBoundingBoxQueryBuilder(String name) { public GeoBoundingBoxQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -74,14 +74,14 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
double bottom = Double.NaN; double bottom = Double.NaN;
double left = Double.NaN; double left = Double.NaN;
double right = Double.NaN; double right = Double.NaN;
String queryName = null; String queryName = null;
String currentFieldName = null; String currentFieldName = null;
XContentParser.Token token; XContentParser.Token token;
boolean normalize = true; boolean normalize = true;
GeoPoint sparse = new GeoPoint(); GeoPoint sparse = new GeoPoint();
String type = "memory"; String type = "memory";
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
@ -148,7 +148,7 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
final GeoPoint bottomRight = new GeoPoint(bottom, right); final GeoPoint bottomRight = new GeoPoint(bottom, right);
if (normalize) { if (normalize) {
// Special case: if the difference bettween the left and right is 360 and the right is greater than the left, we are asking for // Special case: if the difference bettween the left and right is 360 and the right is greater than the left, we are asking for
// the complete longitude range so need to set longitude to the complete longditude range // the complete longitude range so need to set longitude to the complete longditude range
boolean completeLonRange = ((right - left) % 360 == 0 && right > left); boolean completeLonRange = ((right - left) % 360 == 0 && right > left);
GeoUtils.normalizePoint(topLeft, true, !completeLonRange); GeoUtils.normalizePoint(topLeft, true, !completeLonRange);
@ -183,5 +183,10 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
parseContext.addNamedQuery(queryName, filter); parseContext.addNamedQuery(queryName, filter);
} }
return filter; return filter;
} }
@Override
public GeoBoundingBoxQueryBuilder getBuilderPrototype() {
return GeoBoundingBoxQueryBuilder.PROTOTYPE;
}
} }

View File

@ -46,6 +46,8 @@ public class GeoDistanceQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final GeoDistanceQueryBuilder PROTOTYPE = new GeoDistanceQueryBuilder(null);
public GeoDistanceQueryBuilder(String name) { public GeoDistanceQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -162,4 +162,9 @@ public class GeoDistanceQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public GeoDistanceQueryBuilder getBuilderPrototype() {
return GeoDistanceQueryBuilder.PROTOTYPE;
}
} }

View File

@ -48,6 +48,8 @@ public class GeoDistanceRangeQueryBuilder extends QueryBuilder {
private String optimizeBbox; private String optimizeBbox;
static final GeoDistanceRangeQueryBuilder PROTOTYPE = new GeoDistanceRangeQueryBuilder(null);
public GeoDistanceRangeQueryBuilder(String name) { public GeoDistanceRangeQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -201,4 +201,9 @@ public class GeoDistanceRangeQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public GeoDistanceRangeQueryBuilder getBuilderPrototype() {
return GeoDistanceRangeQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class GeoPolygonQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final GeoPolygonQueryBuilder PROTOTYPE = new GeoPolygonQueryBuilder(null);
public GeoPolygonQueryBuilder(String name) { public GeoPolygonQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -150,4 +150,9 @@ public class GeoPolygonQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public GeoPolygonQueryBuilder getBuilderPrototype() {
return GeoPolygonQueryBuilder.PROTOTYPE;
}
} }

View File

@ -49,6 +49,8 @@ public class GeoShapeQueryBuilder extends QueryBuilder {
private ShapeRelation relation = null; private ShapeRelation relation = null;
static final GeoShapeQueryBuilder PROTOTYPE = new GeoShapeQueryBuilder(null, null);
/** /**
* Creates a new GeoShapeQueryBuilder whose Filter will be against the * Creates a new GeoShapeQueryBuilder whose Filter will be against the
* given field name using the given Shape * given field name using the given Shape

View File

@ -189,4 +189,9 @@ public class GeoShapeQueryParser extends BaseQueryParserTemp {
throw new IllegalArgumentException(""); throw new IllegalArgumentException("");
} }
} }
@Override
public GeoShapeQueryBuilder getBuilderPrototype() {
return GeoShapeQueryBuilder.PROTOTYPE;
}
} }

View File

@ -98,6 +98,7 @@ public class GeohashCellQuery {
private String geohash; private String geohash;
private int levels = -1; private int levels = -1;
private boolean neighbors; private boolean neighbors;
private static final Builder PROTOTYPE = new Builder(null);
public Builder(String field) { public Builder(String field) {
@ -270,5 +271,10 @@ public class GeohashCellQuery {
return filter; return filter;
} }
@Override
public GeohashCellQuery.Builder getBuilderPrototype() {
return Builder.PROTOTYPE;
}
} }
} }

View File

@ -45,6 +45,8 @@ public class HasChildQueryBuilder extends QueryBuilder implements BoostableQuery
private QueryInnerHitBuilder innerHit = null; private QueryInnerHitBuilder innerHit = null;
static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder(null, null);
public HasChildQueryBuilder(String type, QueryBuilder queryBuilder) { public HasChildQueryBuilder(String type, QueryBuilder queryBuilder) {
this.childType = type; this.childType = type;
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;

View File

@ -187,4 +187,9 @@ public class HasChildQueryParser extends BaseQueryParserTemp {
query.setBoost(boost); query.setBoost(boost);
return query; return query;
} }
@Override
public HasChildQueryBuilder getBuilderPrototype() {
return HasChildQueryBuilder.PROTOTYPE;
}
} }

View File

@ -35,6 +35,7 @@ public class HasParentQueryBuilder extends QueryBuilder implements BoostableQuer
private float boost = 1.0f; private float boost = 1.0f;
private String queryName; private String queryName;
private QueryInnerHitBuilder innerHit = null; private QueryInnerHitBuilder innerHit = null;
static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder(null, null);
/** /**
* @param parentType The parent type * @param parentType The parent type

View File

@ -203,4 +203,9 @@ public class HasParentQueryParser extends BaseQueryParserTemp {
} }
} }
@Override
public HasParentQueryBuilder getBuilderPrototype() {
return HasParentQueryBuilder.PROTOTYPE;
}
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.queries.TermsQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
@ -49,6 +50,8 @@ public class IdsQueryBuilder extends QueryBuilder<IdsQueryBuilder> implements Bo
private String queryName; private String queryName;
static final IdsQueryBuilder PROTOTYPE = new IdsQueryBuilder();
/** /**
* Creates a new IdsQueryBuilder by optionally providing the types of the documents to look for * Creates a new IdsQueryBuilder by optionally providing the types of the documents to look for
*/ */

View File

@ -107,4 +107,9 @@ public class IdsQueryParser extends BaseQueryParser {
query.validate(); query.validate();
return query; return query;
} }
@Override
public IdsQueryBuilder getBuilderPrototype() {
return IdsQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class IndicesQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final IndicesQueryBuilder PROTOTYPE = new IndicesQueryBuilder(null);
public IndicesQueryBuilder(QueryBuilder queryBuilder, String... indices) { public IndicesQueryBuilder(QueryBuilder queryBuilder, String... indices) {
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;
this.indices = indices; this.indices = indices;

View File

@ -157,4 +157,9 @@ public class IndicesQueryParser extends BaseQueryParserTemp {
} }
return false; return false;
} }
@Override
public IndicesQueryBuilder getBuilderPrototype() {
return IndicesQueryBuilder.PROTOTYPE;
}
} }

View File

@ -32,6 +32,7 @@ public class LimitQueryBuilder extends QueryBuilder {
public static final String NAME = "limit"; public static final String NAME = "limit";
private final int limit; private final int limit;
static final LimitQueryBuilder PROTOTYPE = new LimitQueryBuilder(-1);
public LimitQueryBuilder(int limit) { public LimitQueryBuilder(int limit) {
this.limit = limit; this.limit = limit;

View File

@ -64,4 +64,9 @@ public class LimitQueryParser extends BaseQueryParserTemp {
// this filter is deprecated and parses to a filter that matches everything // this filter is deprecated and parses to a filter that matches everything
return Queries.newMatchAllQuery(); return Queries.newMatchAllQuery();
} }
@Override
public LimitQueryBuilder getBuilderPrototype() {
return LimitQueryBuilder.PROTOTYPE;
}
} }

View File

@ -37,6 +37,8 @@ public class MatchAllQueryBuilder extends QueryBuilder<MatchAllQueryBuilder> imp
private float boost = 1.0f; private float boost = 1.0f;
static final MatchAllQueryBuilder PROTOTYPE = new MatchAllQueryBuilder();
/** /**
* Sets the boost for this query. Documents matching this query will (in addition to the normal * Sets the boost for this query. Documents matching this query will (in addition to the normal
* weightings) have their score multiplied by the boost provided. * weightings) have their score multiplied by the boost provided.

View File

@ -59,4 +59,9 @@ public class MatchAllQueryParser extends BaseQueryParser {
} }
return queryBuilder; return queryBuilder;
} }
@Override
public MatchAllQueryBuilder getBuilderPrototype() {
return MatchAllQueryBuilder.PROTOTYPE;
}
} }

View File

@ -94,6 +94,8 @@ public class MatchQueryBuilder extends QueryBuilder implements BoostableQueryBui
private String queryName; private String queryName;
static final MatchQueryBuilder PROTOTYPE = new MatchQueryBuilder(null, null);
/** /**
* Constructs a new text query. * Constructs a new text query.
*/ */

View File

@ -178,4 +178,9 @@ public class MatchQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public MatchQueryBuilder getBuilderPrototype() {
return MatchQueryBuilder.PROTOTYPE;
}
} }

View File

@ -38,6 +38,8 @@ public class MissingQueryBuilder extends QueryBuilder {
private Boolean existence; private Boolean existence;
static final MissingQueryBuilder PROTOTYPE = new MissingQueryBuilder(null);
public MissingQueryBuilder(String name) { public MissingQueryBuilder(String name) {
this.name = name; this.name = name;
} }

View File

@ -172,4 +172,9 @@ public class MissingQueryParser extends BaseQueryParserTemp {
} }
return new ConstantScoreQuery(filter); return new ConstantScoreQuery(filter);
} }
@Override
public MissingQueryBuilder getBuilderPrototype() {
return MissingQueryBuilder.PROTOTYPE;
}
} }

View File

@ -152,6 +152,8 @@ public class MoreLikeThisQueryBuilder extends QueryBuilder implements BoostableQ
private Boolean failOnUnsupportedField; private Boolean failOnUnsupportedField;
private String queryName; private String queryName;
static final MoreLikeThisQueryBuilder PROTOTYPE = new MoreLikeThisQueryBuilder();
/** /**
* Constructs a new more like this query which uses the "_all" field. * Constructs a new more like this query which uses the "_all" field.
*/ */

View File

@ -355,4 +355,9 @@ public class MoreLikeThisQueryParser extends BaseQueryParserTemp {
boolQuery.add(query, BooleanClause.Occur.MUST_NOT); boolQuery.add(query, BooleanClause.Occur.MUST_NOT);
} }
} }
@Override
public MoreLikeThisQueryBuilder getBuilderPrototype() {
return MoreLikeThisQueryBuilder.PROTOTYPE;
}
} }

View File

@ -80,6 +80,8 @@ public class MultiMatchQueryBuilder extends QueryBuilder implements BoostableQue
private String queryName; private String queryName;
static final MultiMatchQueryBuilder PROTOTYPE = new MultiMatchQueryBuilder(null);
public enum Type { public enum Type {
/** /**

View File

@ -197,4 +197,9 @@ public class MultiMatchQueryParser extends BaseQueryParserTemp {
fieldNameWithBoosts.put(fField, fBoost); fieldNameWithBoosts.put(fField, fBoost);
} }
} }
@Override
public MultiMatchQueryBuilder getBuilderPrototype() {
return MultiMatchQueryBuilder.PROTOTYPE;
}
} }

View File

@ -41,10 +41,21 @@ public class NestedQueryBuilder extends QueryBuilder implements BoostableQueryBu
private QueryInnerHitBuilder innerHit; private QueryInnerHitBuilder innerHit;
static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder();
public NestedQueryBuilder(String path, QueryBuilder queryBuilder) { public NestedQueryBuilder(String path, QueryBuilder queryBuilder) {
this.path = path; this.path = path;
this.queryBuilder = Objects.requireNonNull(queryBuilder); this.queryBuilder = Objects.requireNonNull(queryBuilder);
} }
/**
* private constructor only used internally
*/
private NestedQueryBuilder() {
this.path = null;
this.queryBuilder = null;
}
/** /**
* The score mode. * The score mode.
*/ */

View File

@ -161,4 +161,9 @@ public class NestedQueryParser extends BaseQueryParserTemp {
} }
} }
@Override
public NestedQueryBuilder getBuilderPrototype() {
return NestedQueryBuilder.PROTOTYPE;
}
} }

View File

@ -35,10 +35,19 @@ public class NotQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final NotQueryBuilder PROTOTYPE = new NotQueryBuilder();
public NotQueryBuilder(QueryBuilder filter) { public NotQueryBuilder(QueryBuilder filter) {
this.filter = Objects.requireNonNull(filter); this.filter = Objects.requireNonNull(filter);
} }
/**
* private constructor for internal use
*/
private NotQueryBuilder() {
this.filter = null;
}
public NotQueryBuilder queryName(String queryName) { public NotQueryBuilder queryName(String queryName) {
this.queryName = queryName; this.queryName = queryName;
return this; return this;

View File

@ -94,4 +94,9 @@ public class NotQueryParser extends BaseQueryParserTemp {
} }
return notQuery; return notQuery;
} }
@Override
public NotQueryBuilder getBuilderPrototype() {
return NotQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class OrQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final OrQueryBuilder PROTOTYPE = new OrQueryBuilder();
public OrQueryBuilder(QueryBuilder... filters) { public OrQueryBuilder(QueryBuilder... filters) {
Collections.addAll(this.filters, filters); Collections.addAll(this.filters, filters);
} }

View File

@ -112,4 +112,9 @@ public class OrQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public OrQueryBuilder getBuilderPrototype() {
return OrQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class PrefixQueryBuilder extends MultiTermQueryBuilder implements Boostab
private String queryName; private String queryName;
static final PrefixQueryBuilder PROTOTYPE = new PrefixQueryBuilder(null, null);
/** /**
* A Query that matches documents containing terms with a specified prefix. * A Query that matches documents containing terms with a specified prefix.
* *

View File

@ -115,4 +115,9 @@ public class PrefixQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public PrefixQueryBuilder getBuilderPrototype() {
return PrefixQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class QueryFilterBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final QueryFilterBuilder PROTOTYPE = new QueryFilterBuilder(null);
/** /**
* A filter that simply wraps a query. * A filter that simply wraps a query.
* *

View File

@ -41,4 +41,9 @@ public class QueryFilterParser extends BaseQueryParserTemp {
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
return new ConstantScoreQuery(parseContext.parseInnerQuery()); return new ConstantScoreQuery(parseContext.parseInnerQuery());
} }
@Override
public QueryFilterBuilder getBuilderPrototype() {
return QueryFilterBuilder.PROTOTYPE;
}
} }

View File

@ -59,4 +59,9 @@ public interface QueryParser {
* @throws QueryParsingException * @throws QueryParsingException
*/ */
QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException; QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException;
/**
* @return an empty {@link QueryBuilder} instance for this parser that can be used for deserialization
*/
QueryBuilder getBuilderPrototype();
} }

View File

@ -101,6 +101,8 @@ public class QueryStringQueryBuilder extends QueryBuilder implements BoostableQu
/** To limit effort spent determinizing regexp queries. */ /** To limit effort spent determinizing regexp queries. */
private Integer maxDeterminizedStates; private Integer maxDeterminizedStates;
static final QueryStringQueryBuilder PROTOTYPE = new QueryStringQueryBuilder(null);
public QueryStringQueryBuilder(String queryString) { public QueryStringQueryBuilder(String queryString) {
this.queryString = queryString; this.queryString = queryString;
} }

View File

@ -245,4 +245,9 @@ public class QueryStringQueryParser extends BaseQueryParserTemp {
throw new QueryParsingException(parseContext, "Failed to parse query [" + qpSettings.queryString() + "]", e); throw new QueryParsingException(parseContext, "Failed to parse query [" + qpSettings.queryString() + "]", e);
} }
} }
@Override
public QueryStringQueryBuilder getBuilderPrototype() {
return QueryStringQueryBuilder.PROTOTYPE;
}
} }

View File

@ -59,6 +59,8 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
private String format; private String format;
static final RangeQueryBuilder PROTOTYPE = new RangeQueryBuilder(null);
/** /**
* A Query that matches documents within an range of terms. * A Query that matches documents within an range of terms.
* *

View File

@ -19,12 +19,9 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import org.apache.lucene.search.TermRangeQuery;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import java.io.IOException; import java.io.IOException;
@ -125,4 +122,9 @@ public class RangeQueryParser extends BaseQueryParser {
rangeQuery.validate(); rangeQuery.validate();
return rangeQuery; return rangeQuery;
} }
@Override
public RangeQueryBuilder getBuilderPrototype() {
return RangeQueryBuilder.PROTOTYPE;
}
} }

View File

@ -39,6 +39,7 @@ public class RegexpQueryBuilder extends MultiTermQueryBuilder implements Boostab
private String queryName; private String queryName;
private int maxDeterminizedStates = Operations.DEFAULT_MAX_DETERMINIZED_STATES; private int maxDeterminizedStates = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
private boolean maxDetermizedStatesSet; private boolean maxDetermizedStatesSet;
static final RegexpQueryBuilder PROTOTYPE = new RegexpQueryBuilder(null, null);
/** /**
* Constructs a new term query. * Constructs a new term query.

View File

@ -124,5 +124,10 @@ public class RegexpQueryParser extends BaseQueryParserTemp {
return query; return query;
} }
@Override
public RegexpQueryBuilder getBuilderPrototype() {
return RegexpQueryBuilder.PROTOTYPE;
}
} }

View File

@ -38,6 +38,8 @@ public class ScriptQueryBuilder extends QueryBuilder {
private String queryName; private String queryName;
static final ScriptQueryBuilder PROTOTYPE = new ScriptQueryBuilder(null);
public ScriptQueryBuilder(String script) { public ScriptQueryBuilder(String script) {
this.script = script; this.script = script;
} }

View File

@ -189,4 +189,9 @@ public class ScriptQueryParser extends BaseQueryParserTemp {
}; };
} }
} }
@Override
public ScriptQueryBuilder getBuilderPrototype() {
return ScriptQueryBuilder.PROTOTYPE;
}
} }

View File

@ -43,6 +43,7 @@ public class SimpleQueryStringBuilder extends QueryBuilder {
private Boolean lenient; private Boolean lenient;
private Boolean analyzeWildcard; private Boolean analyzeWildcard;
private Locale locale; private Locale locale;
static final SimpleQueryStringBuilder PROTOTYPE = new SimpleQueryStringBuilder(null);
/** /**
* Operators for the default_operator * Operators for the default_operator

View File

@ -230,4 +230,9 @@ public class SimpleQueryStringParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SimpleQueryStringBuilder getBuilderPrototype() {
return SimpleQueryStringBuilder.PROTOTYPE;
}
} }

View File

@ -33,6 +33,7 @@ public class SpanContainingQueryBuilder extends QueryBuilder implements SpanQuer
private SpanQueryBuilder little; private SpanQueryBuilder little;
private float boost = -1; private float boost = -1;
private String queryName; private String queryName;
static final SpanContainingQueryBuilder PROTOTYPE = new SpanContainingQueryBuilder();
/** /**
* Sets the little clause, it must be contained within {@code big} for a match. * Sets the little clause, it must be contained within {@code big} for a match.

View File

@ -95,4 +95,9 @@ public class SpanContainingQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanContainingQueryBuilder getBuilderPrototype() {
return SpanContainingQueryBuilder.PROTOTYPE;
}
} }

View File

@ -35,6 +35,8 @@ public class SpanFirstQueryBuilder extends QueryBuilder implements SpanQueryBuil
private String queryName; private String queryName;
static final SpanFirstQueryBuilder SPAN_FIRST_QUERY_BUILDER = new SpanFirstQueryBuilder(null, -1);
public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) { public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) {
this.matchBuilder = matchBuilder; this.matchBuilder = matchBuilder;
this.end = end; this.end = end;

View File

@ -93,4 +93,9 @@ public class SpanFirstQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanFirstQueryBuilder getBuilderPrototype() {
return SpanFirstQueryBuilder.SPAN_FIRST_QUERY_BUILDER;
}
} }

View File

@ -26,6 +26,7 @@ public class SpanMultiTermQueryBuilder extends QueryBuilder implements SpanQuery
public static final String NAME = "span_multi"; public static final String NAME = "span_multi";
private MultiTermQueryBuilder multiTermQueryBuilder; private MultiTermQueryBuilder multiTermQueryBuilder;
static final SpanMultiTermQueryBuilder PROTOTYPE = new SpanMultiTermQueryBuilder(null);
public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) { public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) {
this.multiTermQueryBuilder = multiTermQueryBuilder; this.multiTermQueryBuilder = multiTermQueryBuilder;

View File

@ -66,4 +66,9 @@ public class SpanMultiTermQueryParser extends BaseQueryParserTemp {
parser.nextToken(); parser.nextToken();
return new SpanMultiTermQueryWrapper<>((MultiTermQuery) subQuery); return new SpanMultiTermQueryWrapper<>((MultiTermQuery) subQuery);
} }
@Override
public SpanMultiTermQueryBuilder getBuilderPrototype() {
return SpanMultiTermQueryBuilder.PROTOTYPE;
}
} }

View File

@ -40,6 +40,8 @@ public class SpanNearQueryBuilder extends QueryBuilder implements SpanQueryBuild
private String queryName; private String queryName;
static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder();
public SpanNearQueryBuilder clause(SpanQueryBuilder clause) { public SpanNearQueryBuilder clause(SpanQueryBuilder clause) {
clauses.add(clause); clauses.add(clause);
return this; return this;

View File

@ -106,4 +106,9 @@ public class SpanNearQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanNearQueryBuilder getBuilderPrototype() {
return SpanNearQueryBuilder.PROTOTYPE;
}
} }

View File

@ -41,6 +41,8 @@ public class SpanNotQueryBuilder extends QueryBuilder implements SpanQueryBuilde
private String queryName; private String queryName;
static final SpanNotQueryBuilder PROTOTYPE = new SpanNotQueryBuilder();
public SpanNotQueryBuilder include(SpanQueryBuilder include) { public SpanNotQueryBuilder include(SpanQueryBuilder include) {
this.include = include; this.include = include;
return this; return this;

View File

@ -126,4 +126,9 @@ public class SpanNotQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanNotQueryBuilder getBuilderPrototype() {
return SpanNotQueryBuilder.PROTOTYPE;
}
} }

View File

@ -34,6 +34,8 @@ public class SpanOrQueryBuilder extends QueryBuilder implements SpanQueryBuilder
private String queryName; private String queryName;
static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder();
public SpanOrQueryBuilder clause(SpanQueryBuilder clause) { public SpanOrQueryBuilder clause(SpanQueryBuilder clause) {
clauses.add(clause); clauses.add(clause);
return this; return this;

View File

@ -92,4 +92,9 @@ public class SpanOrQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanOrQueryBuilder getBuilderPrototype() {
return SpanOrQueryBuilder.PROTOTYPE;
}
} }

View File

@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.FieldMapper;
public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuilder> implements SpanQueryBuilder { public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuilder> implements SpanQueryBuilder {
public static final String NAME = "span_term"; public static final String NAME = "span_term";
static final SpanTermQueryBuilder PROTOTYPE = new SpanTermQueryBuilder(null, null);
/** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */ /** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */
public SpanTermQueryBuilder(String name, String value) { public SpanTermQueryBuilder(String name, String value) {

View File

@ -92,4 +92,9 @@ public class SpanTermQueryParser extends BaseQueryParser {
result.validate(); result.validate();
return result; return result;
} }
@Override
public SpanTermQueryBuilder getBuilderPrototype() {
return SpanTermQueryBuilder.PROTOTYPE;
}
} }

View File

@ -33,6 +33,7 @@ public class SpanWithinQueryBuilder extends QueryBuilder implements SpanQueryBui
private SpanQueryBuilder little; private SpanQueryBuilder little;
private float boost = -1; private float boost = -1;
private String queryName; private String queryName;
static final SpanWithinQueryBuilder PROTOTYPE = new SpanWithinQueryBuilder();
/** /**
* Sets the little clause, it must be contained within {@code big} for a match. * Sets the little clause, it must be contained within {@code big} for a match.

View File

@ -95,4 +95,9 @@ public class SpanWithinQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public SpanWithinQueryBuilder getBuilderPrototype() {
return SpanWithinQueryBuilder.PROTOTYPE;
}
} }

View File

@ -39,6 +39,8 @@ public class TemplateQueryBuilder extends QueryBuilder {
private ScriptService.ScriptType templateType; private ScriptService.ScriptType templateType;
static final TemplateQueryBuilder PROTOTYPE = new TemplateQueryBuilder(null, null);
/** /**
* @param template the template to use for that query. * @param template the template to use for that query.
* @param vars the parameters to fill the template with. * @param vars the parameters to fill the template with.

View File

@ -155,4 +155,9 @@ public class TemplateQueryParser extends BaseQueryParserTemp {
return type + " " + template; return type + " " + template;
} }
} }
@Override
public TemplateQueryBuilder getBuilderPrototype() {
return TemplateQueryBuilder.PROTOTYPE;
}
} }

View File

@ -31,6 +31,7 @@ import org.elasticsearch.index.mapper.FieldMapper;
public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> implements BoostableQueryBuilder<TermQueryBuilder> { public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> implements BoostableQueryBuilder<TermQueryBuilder> {
public static final String NAME = "term"; public static final String NAME = "term";
static final TermQueryBuilder PROTOTYPE = new TermQueryBuilder(null, null);
/** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */ /** @see BaseTermQueryBuilder#BaseTermQueryBuilder(String, String) */
public TermQueryBuilder(String fieldName, String value) { public TermQueryBuilder(String fieldName, String value) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import org.apache.lucene.search.TermQuery;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -96,4 +95,9 @@ public class TermQueryParser extends BaseQueryParser {
termQuery.validate(); termQuery.validate();
return termQuery; return termQuery;
} }
@Override
public TermQueryBuilder getBuilderPrototype() {
return TermQueryBuilder.PROTOTYPE;
}
} }

View File

@ -45,6 +45,8 @@ public class TermsQueryBuilder extends QueryBuilder<TermsQueryBuilder> {
private String lookupPath; private String lookupPath;
private Boolean lookupCache; private Boolean lookupCache;
static final TermsQueryBuilder PROTOTYPE = new TermsQueryBuilder(null, (Object) null);
/** /**
* A filter for a field based on several terms matching on any of them. * A filter for a field based on several terms matching on any of them.
* *

View File

@ -207,4 +207,9 @@ public class TermsQueryParser extends BaseQueryParserTemp {
} }
return query; return query;
} }
@Override
public TermsQueryBuilder getBuilderPrototype() {
return TermsQueryBuilder.PROTOTYPE;
}
} }

View File

@ -27,6 +27,7 @@ public class TypeQueryBuilder extends QueryBuilder {
public static final String NAME = "type"; public static final String NAME = "type";
private final String type; private final String type;
static final TypeQueryBuilder PROTOTYPE = new TypeQueryBuilder(null);
public TypeQueryBuilder(String type) { public TypeQueryBuilder(String type) {
this.type = type; this.type = type;

View File

@ -62,7 +62,7 @@ public class TypeQueryParser extends BaseQueryParserTemp {
parser.nextToken(); parser.nextToken();
Query filter; Query filter;
//LUCENE 4 UPGRADE document mapper should use bytesref as well? //LUCENE 4 UPGRADE document mapper should use bytesref as well?
DocumentMapper documentMapper = parseContext.mapperService().documentMapper(type.utf8ToString()); DocumentMapper documentMapper = parseContext.mapperService().documentMapper(type.utf8ToString());
if (documentMapper == null) { if (documentMapper == null) {
filter = new TermQuery(new Term(TypeFieldMapper.NAME, type)); filter = new TermQuery(new Term(TypeFieldMapper.NAME, type));
@ -71,4 +71,9 @@ public class TypeQueryParser extends BaseQueryParserTemp {
} }
return filter; return filter;
} }
@Override
public TypeQueryBuilder getBuilderPrototype() {
return TypeQueryBuilder.PROTOTYPE;
}
} }

View File

@ -45,6 +45,8 @@ public class WildcardQueryBuilder extends MultiTermQueryBuilder implements Boost
private String queryName; private String queryName;
static final WildcardQueryBuilder PROTOTYPE = new WildcardQueryBuilder(null, null);
/** /**
* Implements the wildcard search query. Supported wildcards are <tt>*</tt>, which * Implements the wildcard search query. Supported wildcards are <tt>*</tt>, which
* matches any character sequence (including the empty one), and <tt>?</tt>, * matches any character sequence (including the empty one), and <tt>?</tt>,

View File

@ -108,4 +108,9 @@ public class WildcardQueryParser extends BaseQueryParserTemp {
} }
return wildcardQuery; return wildcardQuery;
} }
@Override
public WildcardQueryBuilder getBuilderPrototype() {
return WildcardQueryBuilder.PROTOTYPE;
}
} }

View File

@ -46,6 +46,7 @@ public class WrapperQueryBuilder extends QueryBuilder {
private final byte[] source; private final byte[] source;
private final int offset; private final int offset;
private final int length; private final int length;
static final WrapperQueryBuilder PROTOTYPE = new WrapperQueryBuilder(null, -1, -1);
/** /**
* Creates a query builder given a query provided as a string * Creates a query builder given a query provided as a string

Some files were not shown because too many files have changed in this diff Show More