public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>> extends ToXContentToBytes implements QueryBuilder
Writeable.Reader<V>, Writeable.Writer<V>ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params| Modifier and Type | Field and Description |
|---|---|
protected float |
boost |
static ParseField |
BOOST_FIELD |
static float |
DEFAULT_BOOST
Default for boost to apply to resulting Lucene query.
|
static ParseField |
NAME_FIELD |
protected java.lang.String |
queryName |
EMPTY_PARAMS| Modifier | Constructor and Description |
|---|---|
protected |
AbstractQueryBuilder() |
protected |
AbstractQueryBuilder(StreamInput in) |
| Modifier and Type | Method and Description |
|---|---|
protected QueryValidationException |
addValidationError(java.lang.String validationError,
QueryValidationException validationException) |
float |
boost()
Returns the boost for this query.
|
QB |
boost(float boost)
Sets the boost for this query.
|
protected static java.lang.Object |
convertToBytesRefIfString(java.lang.Object obj)
This helper method checks if the object passed in is a string, if so it
converts it to a
BytesRef. |
protected static java.lang.Object |
convertToStringIfBytesRef(java.lang.Object obj)
This helper method checks if the object passed in is a
BytesRef, if so it
converts it to a utf8 string. |
protected static void |
declareStandardFields(AbstractObjectParser<? extends QueryBuilder,?> parser)
|
protected abstract boolean |
doEquals(QB other)
Indicates whether some other
QueryBuilder object of the same type is "equal to" this one. |
protected abstract int |
doHashCode() |
protected QueryBuilder |
doRewrite(QueryRewriteContext queryShardContext) |
protected abstract org.apache.lucene.search.Query |
doToQuery(QueryShardContext context) |
protected abstract void |
doWriteTo(StreamOutput out) |
protected abstract void |
doXContent(XContentBuilder builder,
ToXContent.Params params) |
boolean |
equals(java.lang.Object obj) |
protected void |
extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)
For internal usage only!
Extracts the inner hits from the query tree.
|
java.lang.String |
getName()
Returns the name that identifies uniquely the query
|
int |
hashCode() |
protected void |
printBoostAndQueryName(XContentBuilder builder) |
java.lang.String |
queryName()
Returns the query name for the query.
|
QB |
queryName(java.lang.String queryName)
Sets the query name for the query.
|
protected static java.util.List<QueryBuilder> |
readQueries(StreamInput in) |
protected static <T> T |
requireValue(T value,
java.lang.String message) |
QueryBuilder |
rewrite(QueryRewriteContext queryShardContext)
Rewrites this query builder into its primitive form.
|
protected static void |
throwParsingExceptionOnMultipleFields(java.lang.String queryName,
XContentLocation contentLocation,
java.lang.String processedFieldName,
java.lang.String currentFieldName) |
org.apache.lucene.search.Query |
toFilter(QueryShardContext context)
Converts this QueryBuilder to an unscored lucene
Query that acts as a filter. |
protected static java.util.Collection<org.apache.lucene.search.Query> |
toQueries(java.util.Collection<QueryBuilder> queryBuilders,
QueryShardContext context)
Helper method to convert collection of
QueryBuilder instances to lucene
Query instances. |
org.apache.lucene.search.Query |
toQuery(QueryShardContext context)
Converts this QueryBuilder to a lucene
Query. |
XContentBuilder |
toXContent(XContentBuilder builder,
ToXContent.Params params) |
protected static void |
writeQueries(StreamOutput out,
java.util.List<? extends QueryBuilder> queries) |
void |
writeTo(StreamOutput out)
Write this into the StreamOutput.
|
buildAsBytes, buildAsBytes, toString, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitrewriteQuerygetWriteableNameisFragmentpublic static final float DEFAULT_BOOST
public static final ParseField NAME_FIELD
public static final ParseField BOOST_FIELD
protected java.lang.String queryName
protected float boost
protected AbstractQueryBuilder()
protected AbstractQueryBuilder(StreamInput in) throws java.io.IOException
java.io.IOExceptionpublic final void writeTo(StreamOutput out) throws java.io.IOException
Writeableprotected abstract void doWriteTo(StreamOutput out) throws java.io.IOException
java.io.IOExceptionpublic XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
toXContent in interface ToXContentjava.io.IOExceptionprotected abstract void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
java.io.IOExceptionprotected void printBoostAndQueryName(XContentBuilder builder) throws java.io.IOException
java.io.IOExceptionpublic final org.apache.lucene.search.Query toQuery(QueryShardContext context) throws java.io.IOException
QueryBuilderQuery.
Returns null if this query should be ignored in the context of
parent queries.toQuery in interface QueryBuildercontext - additional information needed to construct the queriesQuery or null if this query should be ignored upstreamjava.io.IOExceptionpublic final org.apache.lucene.search.Query toFilter(QueryShardContext context) throws java.io.IOException
QueryBuilderQuery that acts as a filter.
Returns null if this query should be ignored in the context of
parent queries.toFilter in interface QueryBuildercontext - additional information needed to construct the queriesQuery or null if this query should be ignored upstreamjava.io.IOExceptionprotected abstract org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
java.io.IOExceptionpublic final QB queryName(java.lang.String queryName)
queryName in interface QueryBuilderpublic final java.lang.String queryName()
queryName in interface QueryBuilderpublic final float boost()
boost in interface QueryBuilderpublic final QB boost(float boost)
boost in interface QueryBuilderprotected final QueryValidationException addValidationError(java.lang.String validationError, QueryValidationException validationException)
public final boolean equals(java.lang.Object obj)
equals in class java.lang.Objectprotected abstract boolean doEquals(QB other)
QueryBuilder object of the same type is "equal to" this one.public final int hashCode()
hashCode in class java.lang.Objectprotected abstract int doHashCode()
protected static java.lang.Object convertToBytesRefIfString(java.lang.Object obj)
BytesRef.obj - the input objectBytesRef representation if input was of type stringprotected static java.lang.Object convertToStringIfBytesRef(java.lang.Object obj)
BytesRef, if so it
converts it to a utf8 string.obj - the input objectBytesRefprotected static java.util.Collection<org.apache.lucene.search.Query> toQueries(java.util.Collection<QueryBuilder> queryBuilders, QueryShardContext context) throws QueryShardException, java.io.IOException
QueryBuilder instances to lucene
Query instances. QueryBuilder that return null calling
their QueryBuilder.toQuery(QueryShardContext) method are not added to the
resulting collection.QueryShardExceptionjava.io.IOExceptionpublic java.lang.String getName()
QueryBuildergetName in interface QueryBuilderprotected static final void writeQueries(StreamOutput out, java.util.List<? extends QueryBuilder> queries) throws java.io.IOException
java.io.IOExceptionprotected static final java.util.List<QueryBuilder> readQueries(StreamInput in) throws java.io.IOException
java.io.IOExceptionpublic final QueryBuilder rewrite(QueryRewriteContext queryShardContext) throws java.io.IOException
QueryBuilderrewrite in interface QueryBuilderjava.io.IOExceptionprotected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws java.io.IOException
java.io.IOExceptionprotected void extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)
protected static <T> T requireValue(T value,
java.lang.String message)
protected static void throwParsingExceptionOnMultipleFields(java.lang.String queryName,
XContentLocation contentLocation,
java.lang.String processedFieldName,
java.lang.String currentFieldName)
protected static void declareStandardFields(AbstractObjectParser<? extends QueryBuilder,?> parser)
boost and query_name parsing to the
AbstractObjectParser passed in. All query builders except
MatchAllQueryBuilder and MatchNoneQueryBuilder support these fields so they
should use this method.