Query refactoring: unify boost and query name
Following the discussion in #11744, move boost and query _name to base class AbstractQueryBuilder with their getters and setters. Unify their serialization code and equals/hashcode handling in the base class too. This guarantess that every query supports both _name and boost and nothing needs to be done around those in subclasses besides properly parsing the fields in the parsers and printing them out as part of the doXContent method in the builders. More specifically, these are the performed changes: - Introduced printBoostAndQueryName utility method in AbstractQueryBuilder that subclasses can use to print out _name and boost in their doXContent method. - readFrom and writeTo are now final methods that take care of _name and boost serialization. Subclasses have to implement doReadFrom and doWriteTo instead. - toQuery is a final method too that takes care of properly applying _name and boost to the lucene query. Subclasses have to implement doToQuery instead. The query returned will have boost and queryName applied automatically. - Removed BoostableQueryBuilder interface, given that every query is boostable after this change. This won't have any negative effect on filters, as the boost simply gets ignored in that case. - Extended equals and hashcode to handle queryName and boost automatically as well. - Update the query test infra so that queryName and boost are tested automatically, and whenever they are forgotten in parser or doXContent tests fail, so this makes things a lot less error-prone - Introduced DEFAULT_BOOST constant to make sure we don't repeat 1.0f all the time for default boost values. SpanQueryBuilder is again a marker interface only. The convenient toQuery that allowed us to override the return type to SpanQuery cannot be supported anymore due to a clash with the toQuery implementation from AbstractQueryBuilder. We have to go back to castin lucene Query to SpanQuery when dealing with span queries unfortunately. Note that this change touches not only the already refactored queries but also the untouched ones, by making sure that we parse _name and boost whenever we need to and that we print them out as part of QueryBuilder#doXContent. This will result in printing out the default boost all the time rather than skipping it in non refactored queries, something that we would have changed anyway as part of the query refactoring. The following are the queries that support boost now while previously they didn't (parser now parses it and builder prints it out): and, exists, fquery, geo_bounding_box, geo_distance, geo_distance_range, geo_hash_cell, geo_polygon, indices, limit, missing, not, or, script, type. The following are the queries that support _name now while previously they didn't (parser now parses it and builder prints it out): boosting, constant_score, function_score, limit, match_all, type. Range query parser supports now _name at the same level as boost too (_name is still supported on the outer object though for bw comp). There are two exceptions that despite have getters and setters for queryName and boost don't really support boost and queryName: query filter and span multi term query. The reason for this is that they only support a single inner object which is another query that they wrap, no other elements. Relates to #11744 Closes #10776 Closes #11974
This commit is contained in:
parent
654dc20897
commit
cab3a68cc0
|
@ -33,6 +33,6 @@ public class ExistsFieldQueryExtension implements FieldQueryExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query query(QueryParseContext parseContext, String queryText) {
|
public Query query(QueryParseContext parseContext, String queryText) {
|
||||||
return new ConstantScoreQuery(ExistsQueryBuilder.newFilter(parseContext, queryText, null));
|
return new ConstantScoreQuery(ExistsQueryBuilder.newFilter(parseContext, queryText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,10 @@ public class MissingFieldQueryExtension implements FieldQueryExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query query(QueryParseContext parseContext, String queryText) {
|
public Query query(QueryParseContext parseContext, String queryText) {
|
||||||
return new ConstantScoreQuery(MissingQueryParser.newFilter(parseContext, queryText,
|
Query query = MissingQueryParser.newFilter(parseContext, queryText, MissingQueryParser.DEFAULT_EXISTENCE_VALUE, MissingQueryParser.DEFAULT_NULL_VALUE);
|
||||||
MissingQueryParser.DEFAULT_EXISTENCE_VALUE, MissingQueryParser.DEFAULT_NULL_VALUE, null));
|
if (query != null) {
|
||||||
|
return new ConstantScoreQuery(query);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,16 +27,24 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all classes producing lucene queries.
|
* Base class for all classes producing lucene queries.
|
||||||
* Supports conversion to BytesReference and creation of lucene Query objects.
|
* Supports conversion to BytesReference and creation of lucene Query objects.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXContentToBytes implements QueryBuilder<QB> {
|
public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> extends ToXContentToBytes implements QueryBuilder<QB> {
|
||||||
|
|
||||||
|
/** Default for boost to apply to resulting Lucene query. Defaults to 1.0*/
|
||||||
|
public static final float DEFAULT_BOOST = 1.0f;
|
||||||
|
|
||||||
|
protected String queryName;
|
||||||
|
protected float boost = DEFAULT_BOOST;
|
||||||
|
|
||||||
protected AbstractQueryBuilder() {
|
protected AbstractQueryBuilder() {
|
||||||
super(XContentType.JSON);
|
super(XContentType.JSON);
|
||||||
|
@ -52,9 +60,27 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
||||||
|
|
||||||
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;
|
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;
|
||||||
|
|
||||||
|
protected void printBoostAndQueryName(XContentBuilder builder) throws IOException {
|
||||||
|
builder.field("boost", boost);
|
||||||
|
if (queryName != null) {
|
||||||
|
builder.field("_name", queryName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//norelease to be made abstract once all query builders override toQuery providing their own specific implementation.
|
public final Query toQuery(QueryParseContext parseContext) throws IOException {
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
Query query = doToQuery(parseContext);
|
||||||
|
if (query != null) {
|
||||||
|
query.setBoost(boost);
|
||||||
|
if (queryName != null) {
|
||||||
|
parseContext.addNamedQuery(queryName, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
//norelease to be made abstract once all query builders override doToQuery providing their own specific implementation.
|
||||||
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
return parseContext.indexQueryParserService().queryParser(getName()).parse(parseContext);
|
return parseContext.indexQueryParserService().queryParser(getName()).parse(parseContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,15 +91,62 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//norelease remove this once all builders implement readFrom themselves
|
/**
|
||||||
@Override
|
* Returns the query name for the query.
|
||||||
public QB readFrom(StreamInput in) throws IOException {
|
*/
|
||||||
return null;
|
@SuppressWarnings("unchecked")
|
||||||
|
public QB queryName(String queryName) {
|
||||||
|
this.queryName = queryName;
|
||||||
|
return (QB) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the query name for the query.
|
||||||
|
*/
|
||||||
|
public final String queryName() {
|
||||||
|
return queryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the boost for this query.
|
||||||
|
*/
|
||||||
|
public final float boost() {
|
||||||
|
return this.boost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public QB boost(float boost) {
|
||||||
|
this.boost = boost;
|
||||||
|
return (QB) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//norelease remove this once all builders implement writeTo themselves
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public final QB readFrom(StreamInput in) throws IOException {
|
||||||
|
QB queryBuilder = doReadFrom(in);
|
||||||
|
queryBuilder.boost = in.readFloat();
|
||||||
|
queryBuilder.queryName = in.readOptionalString();
|
||||||
|
return queryBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
//norelease make this abstract once all builders implement doReadFrom themselves
|
||||||
|
protected QB doReadFrom(StreamInput in) throws IOException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void writeTo(StreamOutput out) throws IOException {
|
||||||
|
doWriteTo(out);
|
||||||
|
out.writeFloat(boost);
|
||||||
|
out.writeOptionalString(queryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//norelease make this abstract once all builders implement doWriteTo themselves
|
||||||
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final QueryValidationException addValidationError(String validationError, QueryValidationException validationException) {
|
protected final QueryValidationException addValidationError(String validationError, QueryValidationException validationException) {
|
||||||
|
@ -90,7 +163,9 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
QB other = (QB) obj;
|
QB other = (QB) obj;
|
||||||
return doEquals(other);
|
return Objects.equals(queryName, other.queryName) &&
|
||||||
|
Objects.equals(boost, other.boost) &&
|
||||||
|
doEquals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +173,17 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
||||||
*/
|
*/
|
||||||
//norelease to be made abstract once all queries are refactored
|
//norelease to be made abstract once all queries are refactored
|
||||||
protected boolean doEquals(QB other) {
|
protected boolean doEquals(QB other) {
|
||||||
throw new UnsupportedOperationException();
|
return super.equals(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
return 31 * Objects.hash(getClass(), queryName, boost) + doHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
//norelease to be made abstract once all queries are refactored
|
||||||
|
protected int doHashCode() {
|
||||||
|
return super.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,8 +44,6 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
|
|
||||||
private final ArrayList<QueryBuilder> filters = Lists.newArrayList();
|
private final ArrayList<QueryBuilder> filters = Lists.newArrayList();
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final AndQueryBuilder PROTOTYPE = new AndQueryBuilder();
|
static final AndQueryBuilder PROTOTYPE = new AndQueryBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,21 +71,6 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
return this.filters;
|
return this.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public AndQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -96,14 +79,12 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
filter.toXContent(builder, params);
|
filter.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
if (filters.isEmpty()) {
|
if (filters.isEmpty()) {
|
||||||
// no filters provided, this should be ignored upstream
|
// no filters provided, this should be ignored upstream
|
||||||
return null;
|
return null;
|
||||||
|
@ -117,9 +98,6 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
query.add(innerQuery, Occur.MUST);
|
query.add(innerQuery, Occur.MUST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,31 +112,28 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(filters, queryName);
|
return Objects.hash(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(AndQueryBuilder other) {
|
protected boolean doEquals(AndQueryBuilder other) {
|
||||||
return Objects.equals(filters, other.filters) &&
|
return Objects.equals(filters, other.filters);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AndQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected AndQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
AndQueryBuilder andQueryBuilder = new AndQueryBuilder();
|
AndQueryBuilder andQueryBuilder = new AndQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
||||||
for (QueryBuilder queryBuilder : queryBuilders) {
|
for (QueryBuilder queryBuilder : queryBuilders) {
|
||||||
andQueryBuilder.add(queryBuilder);
|
andQueryBuilder.add(queryBuilder);
|
||||||
}
|
}
|
||||||
andQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
return andQueryBuilder;
|
return andQueryBuilder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(filters);
|
out.writeNamedWriteableList(filters);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,9 +27,6 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class AndQueryParser extends BaseQueryParser {
|
public class AndQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
|
@ -51,6 +48,7 @@ public class AndQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
XContentParser.Token token = parser.currentToken();
|
XContentParser.Token token = parser.currentToken();
|
||||||
if (token == XContentParser.Token.START_ARRAY) {
|
if (token == XContentParser.Token.START_ARRAY) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
@ -87,6 +85,8 @@ public class AndQueryParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[and] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[and] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ public class AndQueryParser extends BaseQueryParser {
|
||||||
andQuery.add(query);
|
andQuery.add(query);
|
||||||
}
|
}
|
||||||
andQuery.queryName(queryName);
|
andQuery.queryName(queryName);
|
||||||
|
andQuery.boost(boost);
|
||||||
return andQuery;
|
return andQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends AbstractQueryBuilder<QB> implements BoostableQueryBuilder<QB> {
|
public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends AbstractQueryBuilder<QB> {
|
||||||
|
|
||||||
/** Name of field to match against. */
|
/** Name of field to match against. */
|
||||||
protected final String fieldName;
|
protected final String fieldName;
|
||||||
|
@ -35,12 +35,6 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
||||||
/** Value to find matches for. */
|
/** Value to find matches for. */
|
||||||
protected final Object value;
|
protected final Object value;
|
||||||
|
|
||||||
/** Query boost. */
|
|
||||||
protected float boost = 1.0f;
|
|
||||||
|
|
||||||
/** Name of the query. */
|
|
||||||
protected String queryName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new base term query.
|
* Constructs a new base term query.
|
||||||
*
|
*
|
||||||
|
@ -128,48 +122,13 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
||||||
return convertToStringIfBytesRef(this.value);
|
return convertToStringIfBytesRef(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the query name for the query. */
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Sets the query name for the query.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public QB queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return (QB) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the boost for this query. */
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public QB boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return (QB) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(getName());
|
builder.startObject(getName());
|
||||||
if (boost == 1.0f && queryName == null) {
|
builder.startObject(fieldName);
|
||||||
builder.field(fieldName, convertToStringIfBytesRef(this.value));
|
builder.field("value", convertToStringIfBytesRef(this.value));
|
||||||
} else {
|
printBoostAndQueryName(builder);
|
||||||
builder.startObject(fieldName);
|
builder.endObject();
|
||||||
builder.field("value", convertToStringIfBytesRef(this.value));
|
|
||||||
builder.field("boost", boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,33 +146,26 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected final int doHashCode() {
|
||||||
return Objects.hash(getClass(), fieldName, value, boost, queryName);
|
return Objects.hash(getClass(), fieldName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean doEquals(BaseTermQueryBuilder other) {
|
protected final boolean doEquals(BaseTermQueryBuilder other) {
|
||||||
return Objects.equals(fieldName, other.fieldName) &&
|
return Objects.equals(fieldName, other.fieldName) &&
|
||||||
Objects.equals(value, other.value) &&
|
Objects.equals(value, other.value);
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QB readFrom(StreamInput in) throws IOException {
|
protected final QB doReadFrom(StreamInput in) throws IOException {
|
||||||
QB emptyBuilder = createBuilder(in.readString(), in.readGenericValue());
|
return createBuilder(in.readString(), in.readGenericValue());
|
||||||
emptyBuilder.boost = in.readFloat();
|
|
||||||
emptyBuilder.queryName = in.readOptionalString();
|
|
||||||
return emptyBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract QB createBuilder(String fieldName, Object value);
|
protected abstract QB createBuilder(String fieldName, Object value);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(fieldName);
|
out.writeString(fieldName);
|
||||||
out.writeGenericValue(value);
|
out.writeGenericValue(value);
|
||||||
out.writeFloat(boost);
|
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfN
|
||||||
/**
|
/**
|
||||||
* A Query that matches documents matching boolean combinations of other queries.
|
* A Query that matches documents matching boolean combinations of other queries.
|
||||||
*/
|
*/
|
||||||
public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> implements BoostableQueryBuilder<BoolQueryBuilder> {
|
public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "bool";
|
public static final String NAME = "bool";
|
||||||
|
|
||||||
|
@ -57,16 +57,12 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
|
|
||||||
private final List<QueryBuilder> shouldClauses = new ArrayList<>();
|
private final List<QueryBuilder> shouldClauses = new ArrayList<>();
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private boolean disableCoord = DISABLE_COORD_DEFAULT;
|
private boolean disableCoord = DISABLE_COORD_DEFAULT;
|
||||||
|
|
||||||
private boolean adjustPureNegative = ADJUST_PURE_NEGATIVE_DEFAULT;
|
private boolean adjustPureNegative = ADJUST_PURE_NEGATIVE_DEFAULT;
|
||||||
|
|
||||||
private String minimumShouldMatch;
|
private String minimumShouldMatch;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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. No <tt>null</tt> value allowed.
|
* contribute to scoring. No <tt>null</tt> value allowed.
|
||||||
|
@ -137,23 +133,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
return this.shouldClauses;
|
return this.shouldClauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public BoolQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the boost for this query.
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables <tt>Similarity#coord(int,int)</tt> in scoring. Defaults to <tt>false</tt>.
|
* Disables <tt>Similarity#coord(int,int)</tt> in scoring. Defaults to <tt>false</tt>.
|
||||||
*/
|
*/
|
||||||
|
@ -237,21 +216,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
return this.adjustPureNegative;
|
return this.adjustPureNegative;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public BoolQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -259,15 +223,12 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
doXArrayContent("filter", filterClauses, builder, params);
|
doXArrayContent("filter", filterClauses, builder, params);
|
||||||
doXArrayContent("must_not", mustNotClauses, builder, params);
|
doXArrayContent("must_not", mustNotClauses, builder, params);
|
||||||
doXArrayContent("should", shouldClauses, builder, params);
|
doXArrayContent("should", shouldClauses, builder, params);
|
||||||
builder.field("boost", boost);
|
|
||||||
builder.field("disable_coord", disableCoord);
|
builder.field("disable_coord", disableCoord);
|
||||||
builder.field("adjust_pure_negative", adjustPureNegative);
|
builder.field("adjust_pure_negative", adjustPureNegative);
|
||||||
if (minimumShouldMatch != null) {
|
if (minimumShouldMatch != null) {
|
||||||
builder.field("minimum_should_match", minimumShouldMatch);
|
builder.field("minimum_should_match", minimumShouldMatch);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +254,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
if (!hasClauses()) {
|
if (!hasClauses()) {
|
||||||
return new MatchAllDocsQuery();
|
return new MatchAllDocsQuery();
|
||||||
}
|
}
|
||||||
|
@ -304,13 +265,8 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
addBooleanClauses(parseContext, booleanQuery, shouldClauses, BooleanClause.Occur.SHOULD);
|
addBooleanClauses(parseContext, booleanQuery, shouldClauses, BooleanClause.Occur.SHOULD);
|
||||||
addBooleanClauses(parseContext, booleanQuery, filterClauses, BooleanClause.Occur.FILTER);
|
addBooleanClauses(parseContext, booleanQuery, filterClauses, BooleanClause.Occur.FILTER);
|
||||||
|
|
||||||
booleanQuery.setBoost(boost);
|
|
||||||
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
|
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
|
||||||
Query query = adjustPureNegative ? fixNegativeQueryIfNeeded(booleanQuery) : booleanQuery;
|
return adjustPureNegative ? fixNegativeQueryIfNeeded(booleanQuery) : booleanQuery;
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -323,8 +279,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
return validationException;
|
return validationException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addBooleanClauses(QueryParseContext parseContext, BooleanQuery booleanQuery, List<QueryBuilder> clauses, Occur occurs)
|
private static void addBooleanClauses(QueryParseContext parseContext, BooleanQuery booleanQuery, List<QueryBuilder> clauses, Occur occurs) throws IOException {
|
||||||
throws IOException {
|
|
||||||
for (QueryBuilder query : clauses) {
|
for (QueryBuilder query : clauses) {
|
||||||
Query luceneQuery = query.toQuery(parseContext);
|
Query luceneQuery = query.toQuery(parseContext);
|
||||||
if (luceneQuery != null) {
|
if (luceneQuery != null) {
|
||||||
|
@ -334,18 +289,16 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(boost, adjustPureNegative, disableCoord,
|
return Objects.hash(adjustPureNegative, disableCoord,
|
||||||
minimumShouldMatch, queryName, mustClauses, shouldClauses, mustNotClauses, filterClauses);
|
minimumShouldMatch, mustClauses, shouldClauses, mustNotClauses, filterClauses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(BoolQueryBuilder other) {
|
protected boolean doEquals(BoolQueryBuilder other) {
|
||||||
return Objects.equals(boost, other.boost) &&
|
return Objects.equals(adjustPureNegative, other.adjustPureNegative) &&
|
||||||
Objects.equals(adjustPureNegative, other.adjustPureNegative) &&
|
|
||||||
Objects.equals(disableCoord, other.disableCoord) &&
|
Objects.equals(disableCoord, other.disableCoord) &&
|
||||||
Objects.equals(minimumShouldMatch, other.minimumShouldMatch) &&
|
Objects.equals(minimumShouldMatch, other.minimumShouldMatch) &&
|
||||||
Objects.equals(queryName, other.queryName) &&
|
|
||||||
Objects.equals(mustClauses, other.mustClauses) &&
|
Objects.equals(mustClauses, other.mustClauses) &&
|
||||||
Objects.equals(shouldClauses, other.shouldClauses) &&
|
Objects.equals(shouldClauses, other.shouldClauses) &&
|
||||||
Objects.equals(mustNotClauses, other.mustNotClauses) &&
|
Objects.equals(mustNotClauses, other.mustNotClauses) &&
|
||||||
|
@ -353,7 +306,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BoolQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected BoolQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
||||||
boolQueryBuilder.mustClauses.addAll(queryBuilders);
|
boolQueryBuilder.mustClauses.addAll(queryBuilders);
|
||||||
|
@ -363,25 +316,21 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
||||||
boolQueryBuilder.shouldClauses.addAll(queryBuilders);
|
boolQueryBuilder.shouldClauses.addAll(queryBuilders);
|
||||||
queryBuilders = in.readNamedWriteableList();
|
queryBuilders = in.readNamedWriteableList();
|
||||||
boolQueryBuilder.filterClauses.addAll(queryBuilders);
|
boolQueryBuilder.filterClauses.addAll(queryBuilders);
|
||||||
boolQueryBuilder.boost = in.readFloat();
|
|
||||||
boolQueryBuilder.adjustPureNegative = in.readBoolean();
|
boolQueryBuilder.adjustPureNegative = in.readBoolean();
|
||||||
boolQueryBuilder.disableCoord = in.readBoolean();
|
boolQueryBuilder.disableCoord = in.readBoolean();
|
||||||
boolQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
boolQueryBuilder.minimumShouldMatch = in.readOptionalString();
|
boolQueryBuilder.minimumShouldMatch = in.readOptionalString();
|
||||||
return boolQueryBuilder;
|
return boolQueryBuilder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(mustClauses);
|
out.writeNamedWriteableList(mustClauses);
|
||||||
out.writeNamedWriteableList(mustNotClauses);
|
out.writeNamedWriteableList(mustNotClauses);
|
||||||
out.writeNamedWriteableList(shouldClauses);
|
out.writeNamedWriteableList(shouldClauses);
|
||||||
out.writeNamedWriteableList(filterClauses);
|
out.writeNamedWriteableList(filterClauses);
|
||||||
out.writeFloat(boost);
|
|
||||||
out.writeBoolean(adjustPureNegative);
|
out.writeBoolean(adjustPureNegative);
|
||||||
out.writeBoolean(disableCoord);
|
out.writeBoolean(disableCoord);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
out.writeOptionalString(minimumShouldMatch);
|
out.writeOptionalString(minimumShouldMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class BoolQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
boolean disableCoord = BoolQueryBuilder.DISABLE_COORD_DEFAULT;
|
boolean disableCoord = BoolQueryBuilder.DISABLE_COORD_DEFAULT;
|
||||||
boolean adjustPureNegative = BoolQueryBuilder.ADJUST_PURE_NEGATIVE_DEFAULT;
|
boolean adjustPureNegative = BoolQueryBuilder.ADJUST_PURE_NEGATIVE_DEFAULT;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String minimumShouldMatch = null;
|
String minimumShouldMatch = null;
|
||||||
|
|
||||||
final List<QueryBuilder> mustClauses = newArrayList();
|
final List<QueryBuilder> mustClauses = newArrayList();
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch licenses this file to you under
|
|
||||||
* the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query builder which allow setting some boost
|
|
||||||
*/
|
|
||||||
public interface BoostableQueryBuilder<B extends BoostableQueryBuilder<B>> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
B boost(float boost);
|
|
||||||
|
|
||||||
}
|
|
|
@ -40,7 +40,7 @@ import java.util.Objects;
|
||||||
* multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a
|
* multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a
|
||||||
* demoting effect
|
* demoting effect
|
||||||
*/
|
*/
|
||||||
public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuilder> implements BoostableQueryBuilder<BoostingQueryBuilder> {
|
public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "boosting";
|
public static final String NAME = "boosting";
|
||||||
|
|
||||||
|
@ -50,8 +50,6 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
|
|
||||||
private float negativeBoost = -1;
|
private float negativeBoost = -1;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
static final BoostingQueryBuilder PROTOTYPE = new BoostingQueryBuilder();
|
static final BoostingQueryBuilder PROTOTYPE = new BoostingQueryBuilder();
|
||||||
|
|
||||||
public BoostingQueryBuilder() {
|
public BoostingQueryBuilder() {
|
||||||
|
@ -102,29 +100,13 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
return this.negativeBoost;
|
return this.negativeBoost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the boost factor.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public BoostingQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the boost factor.
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
doXContentInnerBuilder(builder, "positive", positiveQuery, params);
|
doXContentInnerBuilder(builder, "positive", positiveQuery, params);
|
||||||
doXContentInnerBuilder(builder, "negative", negativeQuery, params);
|
doXContentInnerBuilder(builder, "negative", negativeQuery, params);
|
||||||
builder.field("negative_boost", negativeBoost);
|
builder.field("negative_boost", negativeBoost);
|
||||||
builder.field("boost", boost);
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +119,7 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
validationException = validateInnerQuery(negativeQuery, validationException);
|
validationException = validateInnerQuery(negativeQuery, validationException);
|
||||||
validationException = validateInnerQuery(positiveQuery, validationException);
|
validationException = validateInnerQuery(positiveQuery, validationException);
|
||||||
return validationException;
|
return validationException;
|
||||||
};
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -145,7 +127,7 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// make upstream queries ignore this query by returning `null`
|
// make upstream queries ignore this query by returning `null`
|
||||||
// if either inner query builder is null or returns null-Query
|
// if either inner query builder is null or returns null-Query
|
||||||
if (positiveQuery == null || negativeQuery == null) {
|
if (positiveQuery == null || negativeQuery == null) {
|
||||||
|
@ -157,41 +139,36 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoostingQuery boostingQuery = new BoostingQuery(positive, negative, negativeBoost);
|
return new BoostingQuery(positive, negative, negativeBoost);
|
||||||
boostingQuery.setBoost(boost);
|
|
||||||
return boostingQuery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(boost, negativeBoost, positiveQuery, negativeQuery);
|
return Objects.hash(negativeBoost, positiveQuery, negativeQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(BoostingQueryBuilder other) {
|
protected boolean doEquals(BoostingQueryBuilder other) {
|
||||||
return Objects.equals(boost, other.boost) &&
|
return Objects.equals(negativeBoost, other.negativeBoost) &&
|
||||||
Objects.equals(negativeBoost, other.negativeBoost) &&
|
|
||||||
Objects.equals(positiveQuery, other.positiveQuery) &&
|
Objects.equals(positiveQuery, other.positiveQuery) &&
|
||||||
Objects.equals(negativeQuery, other.negativeQuery);
|
Objects.equals(negativeQuery, other.negativeQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BoostingQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected BoostingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder positiveQuery = in.readNamedWriteable();
|
QueryBuilder positiveQuery = in.readNamedWriteable();
|
||||||
QueryBuilder negativeQuery = in.readNamedWriteable();
|
QueryBuilder negativeQuery = in.readNamedWriteable();
|
||||||
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder();
|
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder();
|
||||||
boostingQuery.positive(positiveQuery);
|
boostingQuery.positive(positiveQuery);
|
||||||
boostingQuery.negative(negativeQuery);
|
boostingQuery.negative(negativeQuery);
|
||||||
boostingQuery.boost = in.readFloat();
|
|
||||||
boostingQuery.negativeBoost = in.readFloat();
|
boostingQuery.negativeBoost = in.readFloat();
|
||||||
return boostingQuery;
|
return boostingQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(positiveQuery);
|
out.writeNamedWriteable(positiveQuery);
|
||||||
out.writeNamedWriteable(negativeQuery);
|
out.writeNamedWriteable(negativeQuery);
|
||||||
out.writeFloat(boost);
|
|
||||||
out.writeFloat(negativeBoost);
|
out.writeFloat(negativeBoost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,9 @@ public class BoostingQueryParser extends BaseQueryParser {
|
||||||
boolean positiveQueryFound = false;
|
boolean positiveQueryFound = false;
|
||||||
QueryBuilder negativeQuery = null;
|
QueryBuilder negativeQuery = null;
|
||||||
boolean negativeQueryFound = false;
|
boolean negativeQueryFound = false;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
float negativeBoost = -1;
|
float negativeBoost = -1;
|
||||||
|
String queryName = null;
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -67,6 +68,8 @@ public class BoostingQueryParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) {
|
if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) {
|
||||||
negativeBoost = parser.floatValue();
|
negativeBoost = parser.floatValue();
|
||||||
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
} else if ("boost".equals(currentFieldName)) {
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
boost = parser.floatValue();
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,7 +93,7 @@ public class BoostingQueryParser extends BaseQueryParser {
|
||||||
boostingQuery.negative(negativeQuery);
|
boostingQuery.negative(negativeQuery);
|
||||||
boostingQuery.negativeBoost(negativeBoost);
|
boostingQuery.negativeBoost(negativeBoost);
|
||||||
boostingQuery.boost(boost);
|
boostingQuery.boost(boost);
|
||||||
boostingQuery.validate();
|
boostingQuery.queryName(queryName);
|
||||||
return boostingQuery;
|
return boostingQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ import java.util.Objects;
|
||||||
* execution times significantly if applicable.
|
* execution times significantly if applicable.
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> implements BoostableQueryBuilder<CommonTermsQueryBuilder> {
|
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "common";
|
public static final String NAME = "common";
|
||||||
|
|
||||||
|
@ -77,8 +77,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
|
|
||||||
private String analyzer = null;
|
private String analyzer = null;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String lowFreqMinimumShouldMatch = null;
|
private String lowFreqMinimumShouldMatch = null;
|
||||||
|
|
||||||
private String highFreqMinimumShouldMatch = null;
|
private String highFreqMinimumShouldMatch = null;
|
||||||
|
@ -87,8 +85,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
|
|
||||||
private float cutoffFrequency = DEFAULT_CUTOFF_FREQ;
|
private float cutoffFrequency = DEFAULT_CUTOFF_FREQ;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final CommonTermsQueryBuilder PROTOTYPE = new CommonTermsQueryBuilder(null, null);
|
static final CommonTermsQueryBuilder PROTOTYPE = new CommonTermsQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,19 +143,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
return this.analyzer;
|
return this.analyzer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the boost to apply to the query.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CommonTermsQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float boost() {
|
|
||||||
return boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the cutoff document frequency for high / low frequent terms. A value
|
* Sets the cutoff document frequency for high / low frequent terms. A value
|
||||||
* in [0..1] (or absolute number >=1) representing the maximum threshold of
|
* in [0..1] (or absolute number >=1) representing the maximum threshold of
|
||||||
|
@ -211,20 +194,8 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
return this.disableCoord;
|
return this.disableCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public CommonTermsQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.startObject(fieldName);
|
builder.startObject(fieldName);
|
||||||
|
|
||||||
|
@ -235,7 +206,6 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
if (analyzer != null) {
|
if (analyzer != null) {
|
||||||
builder.field("analyzer", analyzer);
|
builder.field("analyzer", analyzer);
|
||||||
}
|
}
|
||||||
builder.field("boost", boost);
|
|
||||||
builder.field("cutoff_frequency", cutoffFrequency);
|
builder.field("cutoff_frequency", cutoffFrequency);
|
||||||
if (lowFreqMinimumShouldMatch != null || highFreqMinimumShouldMatch != null) {
|
if (lowFreqMinimumShouldMatch != null || highFreqMinimumShouldMatch != null) {
|
||||||
builder.startObject("minimum_should_match");
|
builder.startObject("minimum_should_match");
|
||||||
|
@ -247,9 +217,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
@ -260,7 +228,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
String field;
|
String field;
|
||||||
MappedFieldType fieldType = parseContext.fieldMapper(fieldName);
|
MappedFieldType fieldType = parseContext.fieldMapper(fieldName);
|
||||||
if (fieldType != null) {
|
if (fieldType != null) {
|
||||||
|
@ -287,12 +255,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur();
|
Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur();
|
||||||
|
|
||||||
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency, disableCoord, fieldType);
|
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency, disableCoord, fieldType);
|
||||||
commonsQuery.setBoost(boost);
|
return parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);
|
||||||
Query query = parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Query parseQueryString(ExtendedCommonTermsQuery query, Object queryString, String field, Analyzer analyzer,
|
static Query parseQueryString(ExtendedCommonTermsQuery query, Object queryString, String field, Analyzer analyzer,
|
||||||
|
@ -332,53 +295,47 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonTermsQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected CommonTermsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
CommonTermsQueryBuilder commonTermsQueryBuilder = new CommonTermsQueryBuilder(in.readString(), in.readGenericValue());
|
CommonTermsQueryBuilder commonTermsQueryBuilder = new CommonTermsQueryBuilder(in.readString(), in.readGenericValue());
|
||||||
commonTermsQueryBuilder.highFreqOperator = Operator.readOperatorFrom(in);
|
commonTermsQueryBuilder.highFreqOperator = Operator.readOperatorFrom(in);
|
||||||
commonTermsQueryBuilder.lowFreqOperator = Operator.readOperatorFrom(in);
|
commonTermsQueryBuilder.lowFreqOperator = Operator.readOperatorFrom(in);
|
||||||
commonTermsQueryBuilder.analyzer = in.readOptionalString();
|
commonTermsQueryBuilder.analyzer = in.readOptionalString();
|
||||||
commonTermsQueryBuilder.boost = in.readFloat();
|
|
||||||
commonTermsQueryBuilder.lowFreqMinimumShouldMatch = in.readOptionalString();
|
commonTermsQueryBuilder.lowFreqMinimumShouldMatch = in.readOptionalString();
|
||||||
commonTermsQueryBuilder.highFreqMinimumShouldMatch = in.readOptionalString();
|
commonTermsQueryBuilder.highFreqMinimumShouldMatch = in.readOptionalString();
|
||||||
commonTermsQueryBuilder.disableCoord = in.readBoolean();
|
commonTermsQueryBuilder.disableCoord = in.readBoolean();
|
||||||
commonTermsQueryBuilder.cutoffFrequency = in.readFloat();
|
commonTermsQueryBuilder.cutoffFrequency = in.readFloat();
|
||||||
commonTermsQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
return commonTermsQueryBuilder;
|
return commonTermsQueryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(this.fieldName);
|
out.writeString(this.fieldName);
|
||||||
out.writeGenericValue(this.text);
|
out.writeGenericValue(this.text);
|
||||||
highFreqOperator.writeTo(out);
|
highFreqOperator.writeTo(out);
|
||||||
lowFreqOperator.writeTo(out);
|
lowFreqOperator.writeTo(out);
|
||||||
out.writeOptionalString(analyzer);
|
out.writeOptionalString(analyzer);
|
||||||
out.writeFloat(boost);
|
|
||||||
out.writeOptionalString(lowFreqMinimumShouldMatch);
|
out.writeOptionalString(lowFreqMinimumShouldMatch);
|
||||||
out.writeOptionalString(highFreqMinimumShouldMatch);
|
out.writeOptionalString(highFreqMinimumShouldMatch);
|
||||||
out.writeBoolean(disableCoord);
|
out.writeBoolean(disableCoord);
|
||||||
out.writeFloat(cutoffFrequency);
|
out.writeFloat(cutoffFrequency);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(fieldName, text, highFreqOperator, lowFreqOperator, analyzer, boost,
|
return Objects.hash(fieldName, text, highFreqOperator, lowFreqOperator, analyzer,
|
||||||
lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch, disableCoord, cutoffFrequency, queryName);
|
lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch, disableCoord, cutoffFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(CommonTermsQueryBuilder other) {
|
protected boolean doEquals(CommonTermsQueryBuilder other) {
|
||||||
return Objects.equals(fieldName, other.fieldName) &&
|
return Objects.equals(fieldName, other.fieldName) &&
|
||||||
Objects.equals(text, other.text) &&
|
Objects.equals(text, other.text) &&
|
||||||
Objects.equals(highFreqOperator, other.highFreqOperator) &&
|
Objects.equals(highFreqOperator, other.highFreqOperator) &&
|
||||||
Objects.equals(lowFreqOperator, other.lowFreqOperator) &&
|
Objects.equals(lowFreqOperator, other.lowFreqOperator) &&
|
||||||
Objects.equals(analyzer, other.analyzer) &&
|
Objects.equals(analyzer, other.analyzer) &&
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(lowFreqMinimumShouldMatch, other.lowFreqMinimumShouldMatch) &&
|
Objects.equals(lowFreqMinimumShouldMatch, other.lowFreqMinimumShouldMatch) &&
|
||||||
Objects.equals(highFreqMinimumShouldMatch, other.highFreqMinimumShouldMatch) &&
|
Objects.equals(highFreqMinimumShouldMatch, other.highFreqMinimumShouldMatch) &&
|
||||||
Objects.equals(disableCoord, other.disableCoord) &&
|
Objects.equals(disableCoord, other.disableCoord) &&
|
||||||
Objects.equals(cutoffFrequency, other.cutoffFrequency) &&
|
Objects.equals(cutoffFrequency, other.cutoffFrequency);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class CommonTermsQueryParser extends BaseQueryParser {
|
||||||
}
|
}
|
||||||
String fieldName = parser.currentName();
|
String fieldName = parser.currentName();
|
||||||
Object text = null;
|
Object text = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String analyzer = null;
|
String analyzer = null;
|
||||||
String lowFreqMinimumShouldMatch = null;
|
String lowFreqMinimumShouldMatch = null;
|
||||||
String highFreqMinimumShouldMatch = null;
|
String highFreqMinimumShouldMatch = null;
|
||||||
|
@ -124,7 +124,7 @@ public class CommonTermsQueryParser extends BaseQueryParser {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
throw new QueryParsingException(parseContext, "No text specified for text query");
|
throw new QueryParsingException(parseContext, "No text specified for text query");
|
||||||
}
|
}
|
||||||
CommonTermsQueryBuilder commonTermsQuery = new CommonTermsQueryBuilder(fieldName, text)
|
return new CommonTermsQueryBuilder(fieldName, text)
|
||||||
.lowFreqMinimumShouldMatch(lowFreqMinimumShouldMatch)
|
.lowFreqMinimumShouldMatch(lowFreqMinimumShouldMatch)
|
||||||
.highFreqMinimumShouldMatch(highFreqMinimumShouldMatch)
|
.highFreqMinimumShouldMatch(highFreqMinimumShouldMatch)
|
||||||
.analyzer(analyzer)
|
.analyzer(analyzer)
|
||||||
|
@ -134,7 +134,6 @@ public class CommonTermsQueryParser extends BaseQueryParser {
|
||||||
.cutoffFrequency(cutoffFrequency)
|
.cutoffFrequency(cutoffFrequency)
|
||||||
.boost(boost)
|
.boost(boost)
|
||||||
.queryName(queryName);
|
.queryName(queryName);
|
||||||
return commonTermsQuery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,14 +32,12 @@ import java.util.Objects;
|
||||||
* A query that wraps a filter and simply returns a constant score equal to the
|
* A query that wraps a filter and simply returns a constant score equal to the
|
||||||
* query boost for every document in the filter.
|
* query boost for every document in the filter.
|
||||||
*/
|
*/
|
||||||
public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScoreQueryBuilder> implements BoostableQueryBuilder<ConstantScoreQueryBuilder> {
|
public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScoreQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "constant_score";
|
public static final String NAME = "constant_score";
|
||||||
|
|
||||||
private final QueryBuilder filterBuilder;
|
private final QueryBuilder filterBuilder;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
static final ConstantScoreQueryBuilder PROTOTYPE = new ConstantScoreQueryBuilder(null);
|
static final ConstantScoreQueryBuilder PROTOTYPE = new ConstantScoreQueryBuilder(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,33 +57,16 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
||||||
return this.filterBuilder;
|
return this.filterBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ConstantScoreQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the boost factor
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
doXContentInnerBuilder(builder, "filter", filterBuilder, params);
|
doXContentInnerBuilder(builder, "filter", filterBuilder, params);
|
||||||
builder.field("boost", boost);
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// current DSL allows empty inner filter clauses, we ignore them
|
// current DSL allows empty inner filter clauses, we ignore them
|
||||||
if (filterBuilder == null) {
|
if (filterBuilder == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -97,9 +78,7 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Query filter = new ConstantScoreQuery(filterBuilder.toQuery(parseContext));
|
return new ConstantScoreQuery(filterBuilder.toQuery(parseContext));
|
||||||
filter.setBoost(boost);
|
|
||||||
return filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,27 +92,23 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(boost, filterBuilder);
|
return Objects.hash(filterBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(ConstantScoreQueryBuilder other) {
|
protected boolean doEquals(ConstantScoreQueryBuilder other) {
|
||||||
return Objects.equals(boost, other.boost) &&
|
return Objects.equals(filterBuilder, other.filterBuilder);
|
||||||
Objects.equals(filterBuilder, other.filterBuilder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstantScoreQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected ConstantScoreQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerFilterBuilder = in.readNamedWriteable();
|
QueryBuilder innerFilterBuilder = in.readNamedWriteable();
|
||||||
ConstantScoreQueryBuilder constantScoreQueryBuilder = new ConstantScoreQueryBuilder(innerFilterBuilder);
|
return new ConstantScoreQueryBuilder(innerFilterBuilder);
|
||||||
constantScoreQueryBuilder.boost = in.readFloat();
|
|
||||||
return constantScoreQueryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(filterBuilder);
|
out.writeNamedWriteable(filterBuilder);
|
||||||
out.writeFloat(boost);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@ public class ConstantScoreQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
QueryBuilder query = null;
|
QueryBuilder query = null;
|
||||||
boolean queryFound = false;
|
boolean queryFound = false;
|
||||||
float boost = 1.0f;
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -65,7 +66,9 @@ public class ConstantScoreQueryParser extends BaseQueryParser {
|
||||||
throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("boost".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
boost = parser.floatValue();
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[constant_score] query does not support [" + currentFieldName + "]");
|
||||||
|
@ -78,6 +81,7 @@ public class ConstantScoreQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
ConstantScoreQueryBuilder constantScoreBuilder = new ConstantScoreQueryBuilder(query);
|
ConstantScoreQueryBuilder constantScoreBuilder = new ConstantScoreQueryBuilder(query);
|
||||||
constantScoreBuilder.boost(boost);
|
constantScoreBuilder.boost(boost);
|
||||||
|
constantScoreBuilder.queryName(queryName);
|
||||||
return constantScoreBuilder;
|
return constantScoreBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,20 +36,16 @@ import java.util.Objects;
|
||||||
* with the maximum score for that document as produced by any sub-query, plus a tie breaking increment for any
|
* with the maximum score for that document as produced by any sub-query, plus a tie breaking increment for any
|
||||||
* additional matching sub-queries.
|
* additional matching sub-queries.
|
||||||
*/
|
*/
|
||||||
public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder> implements BoostableQueryBuilder<DisMaxQueryBuilder> {
|
public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "dis_max";
|
public static final String NAME = "dis_max";
|
||||||
|
|
||||||
private final ArrayList<QueryBuilder> queries = new ArrayList<>();
|
private final ArrayList<QueryBuilder> queries = new ArrayList<>();
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
/** Default multiplication factor for breaking ties in document scores.*/
|
/** Default multiplication factor for breaking ties in document scores.*/
|
||||||
public static float DEFAULT_TIE_BREAKER = 0.0f;
|
public static float DEFAULT_TIE_BREAKER = 0.0f;
|
||||||
private float tieBreaker = DEFAULT_TIE_BREAKER;
|
private float tieBreaker = DEFAULT_TIE_BREAKER;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final DisMaxQueryBuilder PROTOTYPE = new DisMaxQueryBuilder();
|
static final DisMaxQueryBuilder PROTOTYPE = new DisMaxQueryBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,23 +63,6 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
return this.queries;
|
return this.queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public DisMaxQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the boost for this query
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The score of each non-maximum disjunct for a document is multiplied by this weight
|
* The score of each non-maximum disjunct for a document is multiplied by this weight
|
||||||
* and added into the final score. If non-zero, the value should be small, on the order of 0.1, which says that
|
* and added into the final score. If non-zero, the value should be small, on the order of 0.1, which says that
|
||||||
|
@ -103,51 +82,28 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
return this.tieBreaker;
|
return this.tieBreaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public DisMaxQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field("tie_breaker", tieBreaker);
|
builder.field("tie_breaker", tieBreaker);
|
||||||
builder.field("boost", boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.startArray("queries");
|
builder.startArray("queries");
|
||||||
for (QueryBuilder queryBuilder : queries) {
|
for (QueryBuilder queryBuilder : queries) {
|
||||||
queryBuilder.toXContent(builder, params);
|
queryBuilder.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// return null if there are no queries at all
|
// return null if there are no queries at all
|
||||||
Collection<Query> luceneQueries = toQueries(queries, parseContext);
|
Collection<Query> luceneQueries = toQueries(queries, parseContext);
|
||||||
if (luceneQueries.isEmpty()) {
|
if (luceneQueries.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisjunctionMaxQuery query = new DisjunctionMaxQuery(luceneQueries, tieBreaker);
|
return new DisjunctionMaxQuery(luceneQueries, tieBreaker);
|
||||||
query.setBoost(boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -156,35 +112,29 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DisMaxQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected DisMaxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
DisMaxQueryBuilder disMax = new DisMaxQueryBuilder();
|
DisMaxQueryBuilder disMax = new DisMaxQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
||||||
disMax.queries.addAll(queryBuilders);
|
disMax.queries.addAll(queryBuilders);
|
||||||
disMax.tieBreaker = in.readFloat();
|
disMax.tieBreaker = in.readFloat();
|
||||||
disMax.queryName = in.readOptionalString();
|
|
||||||
disMax.boost = in.readFloat();
|
|
||||||
return disMax;
|
return disMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(queries);
|
out.writeNamedWriteableList(queries);
|
||||||
out.writeFloat(tieBreaker);
|
out.writeFloat(tieBreaker);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
out.writeFloat(boost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(queries, tieBreaker, boost, queryName);
|
return Objects.hash(queries, tieBreaker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(DisMaxQueryBuilder other) {
|
protected boolean doEquals(DisMaxQueryBuilder other) {
|
||||||
return Objects.equals(queries, other.queries) &&
|
return Objects.equals(queries, other.queries) &&
|
||||||
Objects.equals(tieBreaker, other.tieBreaker) &&
|
Objects.equals(tieBreaker, other.tieBreaker);
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class DisMaxQueryParser extends BaseQueryParser {
|
||||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
float tieBreaker = DisMaxQueryBuilder.DEFAULT_TIE_BREAKER;
|
float tieBreaker = DisMaxQueryBuilder.DEFAULT_TIE_BREAKER;
|
||||||
|
|
||||||
final List<QueryBuilder> queries = newArrayList();
|
final List<QueryBuilder> queries = newArrayList();
|
||||||
|
|
|
@ -41,8 +41,6 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder(null);
|
static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder(null);
|
||||||
|
|
||||||
public ExistsQueryBuilder(String name) {
|
public ExistsQueryBuilder(String name) {
|
||||||
|
@ -56,35 +54,17 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the query that can be used when searching for matched_queries per hit.
|
|
||||||
*/
|
|
||||||
public ExistsQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name for the query that can be used when searching for matched_queries per hit.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field("field", name);
|
builder.field("field", name);
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
return newFilter(parseContext, name, queryName);
|
return newFilter(parseContext, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,7 +73,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, String queryName) {
|
public static Query newFilter(QueryParseContext parseContext, String fieldPattern) {
|
||||||
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME);
|
||||||
if (fieldNamesFieldType == null) {
|
if (fieldNamesFieldType == null) {
|
||||||
// can only happen when no types exist, so no docs exist either
|
// can only happen when no types exist, so no docs exist either
|
||||||
|
@ -134,35 +114,27 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
||||||
}
|
}
|
||||||
boolFilter.add(filter, BooleanClause.Occur.SHOULD);
|
boolFilter.add(filter, BooleanClause.Occur.SHOULD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, boolFilter);
|
|
||||||
}
|
|
||||||
return new ConstantScoreQuery(boolFilter);
|
return new ConstantScoreQuery(boolFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(name, queryName);
|
return Objects.hash(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(ExistsQueryBuilder other) {
|
protected boolean doEquals(ExistsQueryBuilder other) {
|
||||||
return Objects.equals(name, other.name) &&
|
return Objects.equals(name, other.name);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExistsQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected ExistsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
ExistsQueryBuilder newQuery = new ExistsQueryBuilder(in.readString());
|
return new ExistsQueryBuilder(in.readString());
|
||||||
newQuery.queryName = in.readOptionalString();
|
|
||||||
return newQuery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(name);
|
out.writeString(name);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class ExistsQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
String fieldPattern = null;
|
String fieldPattern = null;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
@ -55,6 +56,8 @@ public class ExistsQueryParser extends BaseQueryParser {
|
||||||
fieldPattern = parser.text();
|
fieldPattern = parser.text();
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[exists] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[exists] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -67,6 +70,7 @@ public class ExistsQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
ExistsQueryBuilder builder = new ExistsQueryBuilder(fieldPattern);
|
ExistsQueryBuilder builder = new ExistsQueryBuilder(fieldPattern);
|
||||||
builder.queryName(queryName);
|
builder.queryName(queryName);
|
||||||
|
builder.boost(boost);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,6 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
||||||
|
|
||||||
static final FQueryFilterBuilder PROTOTYPE = new FQueryFilterBuilder(null);
|
static final FQueryFilterBuilder PROTOTYPE = new FQueryFilterBuilder(null);
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private final QueryBuilder queryBuilder;
|
private final QueryBuilder queryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,33 +59,16 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
||||||
return this.queryBuilder;
|
return this.queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public FQueryFilterBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name for the filter that can be used when searching for matched_filters per hit
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(FQueryFilterBuilder.NAME);
|
builder.startObject(FQueryFilterBuilder.NAME);
|
||||||
doXContentInnerBuilder(builder, "query", queryBuilder, params);
|
doXContentInnerBuilder(builder, "query", queryBuilder, params);
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// inner query builder can potentially be `null`, in that case we ignore it
|
// inner query builder can potentially be `null`, in that case we ignore it
|
||||||
if (this.queryBuilder == null) {
|
if (this.queryBuilder == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -96,11 +77,7 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
||||||
if (innerQuery == null) {
|
if (innerQuery == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Query query = new ConstantScoreQuery(innerQuery);
|
return new ConstantScoreQuery(innerQuery);
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,28 +86,25 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(queryBuilder, queryName);
|
return Objects.hash(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(FQueryFilterBuilder other) {
|
protected boolean doEquals(FQueryFilterBuilder other) {
|
||||||
return Objects.equals(queryBuilder, other.queryBuilder) &&
|
return Objects.equals(queryBuilder, other.queryBuilder);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FQueryFilterBuilder readFrom(StreamInput in) throws IOException {
|
protected FQueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
||||||
FQueryFilterBuilder fquery = new FQueryFilterBuilder(innerQueryBuilder);
|
FQueryFilterBuilder fquery = new FQueryFilterBuilder(innerQueryBuilder);
|
||||||
fquery.queryName = in.readOptionalString();
|
|
||||||
return fquery;
|
return fquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeNamedWriteable(queryBuilder);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class FQueryFilterParser extends BaseQueryParser {
|
||||||
QueryBuilder wrappedQuery = null;
|
QueryBuilder wrappedQuery = null;
|
||||||
boolean queryFound = false;
|
boolean queryFound = false;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -65,6 +66,8 @@ public class FQueryFilterParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[fquery] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[fquery] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -78,6 +81,7 @@ public class FQueryFilterParser extends BaseQueryParser {
|
||||||
}
|
}
|
||||||
FQueryFilterBuilder queryBuilder = new FQueryFilterBuilder(wrappedQuery);
|
FQueryFilterBuilder queryBuilder = new FQueryFilterBuilder(wrappedQuery);
|
||||||
queryBuilder.queryName(queryName);
|
queryBuilder.queryName(queryName);
|
||||||
|
queryBuilder.boost(boost);
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.spans.FieldMaskingSpanQuery;
|
import org.apache.lucene.search.spans.FieldMaskingSpanQuery;
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
import org.apache.lucene.search.spans.SpanQuery;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -29,7 +30,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder<FieldMaskingSpanQueryBuilder>, BoostableQueryBuilder<FieldMaskingSpanQueryBuilder> {
|
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder<FieldMaskingSpanQueryBuilder>{
|
||||||
|
|
||||||
public static final String NAME = "field_masking_span";
|
public static final String NAME = "field_masking_span";
|
||||||
|
|
||||||
|
@ -37,10 +38,6 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
|
|
||||||
private final String fieldName;
|
private final String fieldName;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final FieldMaskingSpanQueryBuilder PROTOTYPE = new FieldMaskingSpanQueryBuilder();
|
static final FieldMaskingSpanQueryBuilder PROTOTYPE = new FieldMaskingSpanQueryBuilder();
|
||||||
|
|
||||||
private FieldMaskingSpanQueryBuilder() {
|
private FieldMaskingSpanQueryBuilder() {
|
||||||
|
@ -73,61 +70,25 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
return this.queryBuilder;
|
return this.queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FieldMaskingSpanQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the boost factor for this query
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public FieldMaskingSpanQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name for this query
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
doXContentInnerBuilder(builder, "query", queryBuilder, params);
|
doXContentInnerBuilder(builder, "query", queryBuilder, params);
|
||||||
builder.field("field", fieldName);
|
builder.field("field", fieldName);
|
||||||
builder.field("boost", boost);
|
printBoostAndQueryName(builder);
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected SpanQuery doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
String fieldInQuery = fieldName;
|
String fieldInQuery = fieldName;
|
||||||
MappedFieldType fieldType = parseContext.fieldMapper(fieldName);
|
MappedFieldType fieldType = parseContext.fieldMapper(fieldName);
|
||||||
if (fieldType != null) {
|
if (fieldType != null) {
|
||||||
fieldInQuery = fieldType.names().indexName();
|
fieldInQuery = fieldType.names().indexName();
|
||||||
}
|
}
|
||||||
SpanQuery innerQuery = queryBuilder.toQuery(parseContext);
|
Query innerQuery = queryBuilder.toQuery(parseContext);
|
||||||
|
assert innerQuery instanceof SpanQuery;
|
||||||
FieldMaskingSpanQuery query = new FieldMaskingSpanQuery(innerQuery, fieldInQuery);
|
return new FieldMaskingSpanQuery((SpanQuery)innerQuery, fieldInQuery);
|
||||||
query.setBoost(boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,33 +101,26 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMaskingSpanQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected FieldMaskingSpanQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
||||||
FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder((SpanQueryBuilder) innerQueryBuilder, in.readString());
|
return new FieldMaskingSpanQueryBuilder((SpanQueryBuilder) innerQueryBuilder, in.readString());
|
||||||
queryBuilder.queryName = in.readOptionalString();
|
|
||||||
queryBuilder.boost = in.readFloat();
|
|
||||||
return queryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeNamedWriteable(queryBuilder);
|
||||||
out.writeString(fieldName);
|
out.writeString(fieldName);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
out.writeFloat(boost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(queryBuilder, fieldName, boost, queryName);
|
return Objects.hash(queryBuilder, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(FieldMaskingSpanQueryBuilder other) {
|
protected boolean doEquals(FieldMaskingSpanQueryBuilder other) {
|
||||||
return Objects.equals(queryBuilder, other.queryBuilder) &&
|
return Objects.equals(queryBuilder, other.queryBuilder) &&
|
||||||
Objects.equals(fieldName, other.fieldName) &&
|
Objects.equals(fieldName, other.fieldName);
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class FieldMaskingSpanQueryParser extends BaseQueryParser {
|
||||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
SpanQueryBuilder inner = null;
|
SpanQueryBuilder inner = null;
|
||||||
String field = null;
|
String field = null;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.io.IOException;
|
||||||
* @deprecated Use {@link BoolQueryBuilder} instead.
|
* @deprecated Use {@link BoolQueryBuilder} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuilder> implements BoostableQueryBuilder<FilteredQueryBuilder> {
|
public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "filtered";
|
public static final String NAME = "filtered";
|
||||||
|
|
||||||
|
@ -37,10 +37,6 @@ public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuil
|
||||||
|
|
||||||
private final QueryBuilder filterBuilder;
|
private final QueryBuilder filterBuilder;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final FilteredQueryBuilder PROTOTYPE = new FilteredQueryBuilder(null, null);
|
static final FilteredQueryBuilder PROTOTYPE = new FilteredQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,24 +50,6 @@ public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuil
|
||||||
this.filterBuilder = filterBuilder;
|
this.filterBuilder = filterBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public FilteredQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public FilteredQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -83,12 +61,7 @@ public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuil
|
||||||
builder.field("filter");
|
builder.field("filter");
|
||||||
filterBuilder.toXContent(builder, params);
|
filterBuilder.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class FilteredQueryParser extends BaseQueryParserTemp {
|
||||||
Query query = Queries.newMatchAllQuery();
|
Query query = Queries.newMatchAllQuery();
|
||||||
Query filter = null;
|
Query filter = null;
|
||||||
boolean filterFound = false;
|
boolean filterFound = false;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* A Query that does fuzzy matching for a specific value.
|
* A Query that does fuzzy matching for a specific value.
|
||||||
*/
|
*/
|
||||||
public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements BoostableQueryBuilder<FuzzyQueryBuilder> {
|
public class FuzzyQueryBuilder extends MultiTermQueryBuilder {
|
||||||
|
|
||||||
public static final String NAME = "fuzzy";
|
public static final String NAME = "fuzzy";
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
|
||||||
|
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private Fuzziness fuzziness;
|
private Fuzziness fuzziness;
|
||||||
|
|
||||||
private Integer prefixLength;
|
private Integer prefixLength;
|
||||||
|
@ -48,8 +46,6 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
|
||||||
|
|
||||||
private String rewrite;
|
private String rewrite;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final FuzzyQueryBuilder PROTOTYPE = new FuzzyQueryBuilder(null, null);
|
static final FuzzyQueryBuilder PROTOTYPE = new FuzzyQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,16 +59,6 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public FuzzyQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FuzzyQueryBuilder fuzziness(Fuzziness fuzziness) {
|
public FuzzyQueryBuilder fuzziness(Fuzziness fuzziness) {
|
||||||
this.fuzziness = fuzziness;
|
this.fuzziness = fuzziness;
|
||||||
return this;
|
return this;
|
||||||
|
@ -98,22 +84,11 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public FuzzyQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.startObject(name);
|
builder.startObject(name);
|
||||||
builder.field("value", value);
|
builder.field("value", value);
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (transpositions != null) {
|
if (transpositions != null) {
|
||||||
builder.field("transpositions", transpositions);
|
builder.field("transpositions", transpositions);
|
||||||
}
|
}
|
||||||
|
@ -129,9 +104,7 @@ public class FuzzyQueryBuilder extends MultiTermQueryBuilder implements Boostabl
|
||||||
if (rewrite != null) {
|
if (rewrite != null) {
|
||||||
builder.field("rewrite", rewrite);
|
builder.field("rewrite", rewrite);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.unit.Fuzziness;
|
import org.elasticsearch.common.unit.Fuzziness;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.query.support.QueryParsers;
|
import org.elasticsearch.index.query.support.QueryParsers;
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ public class FuzzyQueryParser extends BaseQueryParserTemp {
|
||||||
String fieldName = parser.currentName();
|
String fieldName = parser.currentName();
|
||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
Fuzziness fuzziness = DEFAULT_FUZZINESS;
|
Fuzziness fuzziness = DEFAULT_FUZZINESS;
|
||||||
int prefixLength = FuzzyQuery.defaultPrefixLength;
|
int prefixLength = FuzzyQuery.defaultPrefixLength;
|
||||||
int maxExpansions = FuzzyQuery.defaultMaxExpansions;
|
int maxExpansions = FuzzyQuery.defaultMaxExpansions;
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
||||||
|
|
||||||
private double[] box = {Double.NaN, Double.NaN, Double.NaN, Double.NaN};
|
private double[] box = {Double.NaN, Double.NaN, Double.NaN, Double.NaN};
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
static final GeoBoundingBoxQueryBuilder PROTOTYPE = new GeoBoundingBoxQueryBuilder(null);
|
static final GeoBoundingBoxQueryBuilder PROTOTYPE = new GeoBoundingBoxQueryBuilder(null);
|
||||||
|
@ -130,14 +129,6 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
||||||
return topRight(GeoHashUtils.decode(geohash));
|
return topRight(GeoHashUtils.decode(geohash));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public GeoBoundingBoxQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the type of executing of the geo bounding box. Can be either `memory` or `indexed`. Defaults
|
* Sets the type of executing of the geo bounding box. Can be either `memory` or `indexed`. Defaults
|
||||||
* to `memory`.
|
* to `memory`.
|
||||||
|
@ -167,13 +158,12 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
||||||
builder.array(BOTTOM_RIGHT, box[RIGHT], box[BOTTOM]);
|
builder.array(BOTTOM_RIGHT, box[RIGHT], box[BOTTOM]);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
builder.field("type", type);
|
builder.field("type", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.geo.GeoUtils;
|
||||||
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.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxQuery;
|
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxQuery;
|
||||||
|
@ -76,6 +75,7 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
|
||||||
double left = Double.NaN;
|
double left = Double.NaN;
|
||||||
double right = Double.NaN;
|
double right = Double.NaN;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -135,6 +135,8 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else if ("normalize".equals(currentFieldName)) {
|
} else if ("normalize".equals(currentFieldName)) {
|
||||||
normalize = parser.booleanValue();
|
normalize = parser.booleanValue();
|
||||||
} else if ("type".equals(currentFieldName)) {
|
} else if ("type".equals(currentFieldName)) {
|
||||||
|
@ -179,7 +181,9 @@ public class GeoBoundingBoxQueryParser extends BaseQueryParserTemp {
|
||||||
throw new QueryParsingException(parseContext, "geo bounding box type [" + type
|
throw new QueryParsingException(parseContext, "geo bounding box type [" + type
|
||||||
+ "] not supported, either 'indexed' or 'memory' are allowed");
|
+ "] not supported, either 'indexed' or 'memory' are allowed");
|
||||||
}
|
}
|
||||||
|
if (filter != null) {
|
||||||
|
filter.setBoost(boost);
|
||||||
|
}
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, filter);
|
parseContext.addNamedQuery(queryName, filter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
||||||
|
|
||||||
private String optimizeBbox;
|
private String optimizeBbox;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final GeoDistanceQueryBuilder PROTOTYPE = new GeoDistanceQueryBuilder(null);
|
static final GeoDistanceQueryBuilder PROTOTYPE = new GeoDistanceQueryBuilder(null);
|
||||||
|
|
||||||
public GeoDistanceQueryBuilder(String name) {
|
public GeoDistanceQueryBuilder(String name) {
|
||||||
|
@ -93,14 +91,6 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public GeoDistanceQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -116,9 +106,7 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
||||||
if (optimizeBbox != null) {
|
if (optimizeBbox != null) {
|
||||||
builder.field("optimize_bbox", optimizeBbox);
|
builder.field("optimize_bbox", optimizeBbox);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
|
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
|
||||||
|
@ -60,6 +59,7 @@ public class GeoDistanceQueryParser extends BaseQueryParserTemp {
|
||||||
|
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
GeoPoint point = new GeoPoint();
|
GeoPoint point = new GeoPoint();
|
||||||
|
@ -121,6 +121,8 @@ public class GeoDistanceQueryParser extends BaseQueryParserTemp {
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
|
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
|
||||||
optimizeBbox = parser.textOrNull();
|
optimizeBbox = parser.textOrNull();
|
||||||
} else if ("normalize".equals(currentFieldName)) {
|
} else if ("normalize".equals(currentFieldName)) {
|
||||||
|
@ -161,6 +163,7 @@ public class GeoDistanceQueryParser extends BaseQueryParserTemp {
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, query);
|
parseContext.addNamedQuery(queryName, query);
|
||||||
}
|
}
|
||||||
|
query.setBoost(boost);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
||||||
|
|
||||||
private GeoDistance geoDistance;
|
private GeoDistance geoDistance;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private String optimizeBbox;
|
private String optimizeBbox;
|
||||||
|
|
||||||
static final GeoDistanceRangeQueryBuilder PROTOTYPE = new GeoDistanceRangeQueryBuilder(null);
|
static final GeoDistanceRangeQueryBuilder PROTOTYPE = new GeoDistanceRangeQueryBuilder(null);
|
||||||
|
@ -129,14 +127,6 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public GeoDistanceRangeQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -155,9 +145,7 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
||||||
if (optimizeBbox != null) {
|
if (optimizeBbox != null) {
|
||||||
builder.field("optimize_bbox", optimizeBbox);
|
builder.field("optimize_bbox", optimizeBbox);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
|
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
|
||||||
|
@ -60,6 +59,7 @@ public class GeoDistanceRangeQueryParser extends BaseQueryParserTemp {
|
||||||
|
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
GeoPoint point = new GeoPoint();
|
GeoPoint point = new GeoPoint();
|
||||||
|
@ -151,6 +151,8 @@ public class GeoDistanceRangeQueryParser extends BaseQueryParserTemp {
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
|
} else if ("optimize_bbox".equals(currentFieldName) || "optimizeBbox".equals(currentFieldName)) {
|
||||||
optimizeBbox = parser.textOrNull();
|
optimizeBbox = parser.textOrNull();
|
||||||
} else if ("normalize".equals(currentFieldName)) {
|
} else if ("normalize".equals(currentFieldName)) {
|
||||||
|
@ -200,6 +202,7 @@ public class GeoDistanceRangeQueryParser extends BaseQueryParserTemp {
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, query);
|
parseContext.addNamedQuery(queryName, query);
|
||||||
}
|
}
|
||||||
|
query.setBoost(boost);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||||
|
|
||||||
private final List<GeoPoint> shell = Lists.newArrayList();
|
private final List<GeoPoint> shell = Lists.newArrayList();
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final GeoPolygonQueryBuilder PROTOTYPE = new GeoPolygonQueryBuilder(null);
|
static final GeoPolygonQueryBuilder PROTOTYPE = new GeoPolygonQueryBuilder(null);
|
||||||
|
|
||||||
public GeoPolygonQueryBuilder(String name) {
|
public GeoPolygonQueryBuilder(String name) {
|
||||||
|
@ -51,7 +49,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||||
*
|
*
|
||||||
* @param lat The latitude
|
* @param lat The latitude
|
||||||
* @param lon The longitude
|
* @param lon The longitude
|
||||||
* @return
|
* @return the current builder
|
||||||
*/
|
*/
|
||||||
public GeoPolygonQueryBuilder addPoint(double lat, double lon) {
|
public GeoPolygonQueryBuilder addPoint(double lat, double lon) {
|
||||||
return addPoint(new GeoPoint(lat, lon));
|
return addPoint(new GeoPoint(lat, lon));
|
||||||
|
@ -66,14 +64,6 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public GeoPolygonQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -86,9 +76,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.elasticsearch.common.geo.GeoPoint;
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.geo.GeoUtils;
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
|
@ -28,7 +27,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoPolygonQuery;
|
import org.elasticsearch.index.search.geo.GeoPolygonQuery;
|
||||||
|
@ -72,6 +70,7 @@ public class GeoPolygonQueryParser extends BaseQueryParserTemp {
|
||||||
boolean normalizeLon = true;
|
boolean normalizeLon = true;
|
||||||
boolean normalizeLat = true;
|
boolean normalizeLat = true;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -104,6 +103,8 @@ public class GeoPolygonQueryParser extends BaseQueryParserTemp {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else if ("normalize".equals(currentFieldName)) {
|
} else if ("normalize".equals(currentFieldName)) {
|
||||||
normalizeLat = parser.booleanValue();
|
normalizeLat = parser.booleanValue();
|
||||||
normalizeLon = parser.booleanValue();
|
normalizeLon = parser.booleanValue();
|
||||||
|
@ -149,6 +150,7 @@ public class GeoPolygonQueryParser extends BaseQueryParserTemp {
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, query);
|
parseContext.addNamedQuery(queryName, query);
|
||||||
}
|
}
|
||||||
|
query.setBoost(boost);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* {@link QueryBuilder} that builds a GeoShape Filter
|
* {@link QueryBuilder} that builds a GeoShape Filter
|
||||||
*/
|
*/
|
||||||
public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuilder> implements BoostableQueryBuilder<GeoShapeQueryBuilder> {
|
public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "geo_shape";
|
public static final String NAME = "geo_shape";
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
|
|
||||||
private SpatialStrategy strategy = null;
|
private SpatialStrategy strategy = null;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private final String indexedShapeId;
|
private final String indexedShapeId;
|
||||||
private final String indexedShapeType;
|
private final String indexedShapeType;
|
||||||
|
|
||||||
|
@ -51,8 +49,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
|
|
||||||
private ShapeRelation relation = null;
|
private ShapeRelation relation = null;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -96,17 +92,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
this.indexedShapeType = indexedShapeType;
|
this.indexedShapeType = indexedShapeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the name of the filter
|
|
||||||
*
|
|
||||||
* @param queryName Name of the filter
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public GeoShapeQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines which spatial strategy will be used for building the geo shape filter. When not set, the strategy that
|
* Defines which spatial strategy will be used for building the geo shape filter. When not set, the strategy that
|
||||||
* will be used will be the one that is associated with the geo shape field in the mappings.
|
* will be used will be the one that is associated with the geo shape field in the mappings.
|
||||||
|
@ -152,12 +137,6 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GeoShapeQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -189,13 +168,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.common.geo.ShapeRelation;
|
||||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||||
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.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper;
|
||||||
import org.elasticsearch.index.search.shape.ShapeFetchService;
|
import org.elasticsearch.index.search.shape.ShapeFetchService;
|
||||||
|
@ -158,7 +157,7 @@ public class GeoShapeQueryParser extends BaseQueryParserTemp {
|
||||||
// this strategy doesn't support disjoint anymore: but it did before, including creating lucene fieldcache (!)
|
// this strategy doesn't support disjoint anymore: but it did before, including creating lucene fieldcache (!)
|
||||||
// in this case, execute disjoint as exists && !intersects
|
// in this case, execute disjoint as exists && !intersects
|
||||||
BooleanQuery bool = new BooleanQuery();
|
BooleanQuery bool = new BooleanQuery();
|
||||||
Query exists = ExistsQueryBuilder.newFilter(parseContext, fieldName, null);
|
Query exists = ExistsQueryBuilder.newFilter(parseContext, fieldName);
|
||||||
Filter intersects = strategy.makeFilter(getArgs(shape, ShapeRelation.INTERSECTS));
|
Filter intersects = strategy.makeFilter(getArgs(shape, ShapeRelation.INTERSECTS));
|
||||||
bool.add(exists, BooleanClause.Occur.MUST);
|
bool.add(exists, BooleanClause.Occur.MUST);
|
||||||
bool.add(intersects, BooleanClause.Occur.MUST_NOT);
|
bool.add(intersects, BooleanClause.Occur.MUST_NOT);
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class GeohashCellQuery {
|
||||||
builder.field(PRECISION, levels);
|
builder.field(PRECISION, levels);
|
||||||
}
|
}
|
||||||
builder.field(field, geohash);
|
builder.field(field, geohash);
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,8 @@ public class GeohashCellQuery {
|
||||||
String geohash = null;
|
String geohash = null;
|
||||||
int levels = -1;
|
int levels = -1;
|
||||||
boolean neighbors = false;
|
boolean neighbors = false;
|
||||||
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
if ((token = parser.currentToken()) != Token.START_OBJECT) {
|
if ((token = parser.currentToken()) != Token.START_OBJECT) {
|
||||||
|
@ -217,11 +218,17 @@ public class GeohashCellQuery {
|
||||||
} else if (NEIGHBORS.equals(field)) {
|
} else if (NEIGHBORS.equals(field)) {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
neighbors = parser.booleanValue();
|
neighbors = parser.booleanValue();
|
||||||
|
} else if ("_name".equals(field)) {
|
||||||
|
parser.nextToken();
|
||||||
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(field)) {
|
||||||
|
parser.nextToken();
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
fieldName = field;
|
fieldName = field;
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
if(token == Token.VALUE_STRING) {
|
if(token == Token.VALUE_STRING) {
|
||||||
// A string indicates either a gehash or a lat/lon string
|
// A string indicates either a geohash or a lat/lon string
|
||||||
String location = parser.text();
|
String location = parser.text();
|
||||||
if(location.indexOf(",")>0) {
|
if(location.indexOf(",")>0) {
|
||||||
geohash = GeoUtils.parseGeoPoint(parser).geohash();
|
geohash = GeoUtils.parseGeoPoint(parser).geohash();
|
||||||
|
@ -267,7 +274,12 @@ public class GeohashCellQuery {
|
||||||
} else {
|
} else {
|
||||||
filter = create(parseContext, geoFieldType, geohash, null);
|
filter = create(parseContext, geoFieldType, geohash, null);
|
||||||
}
|
}
|
||||||
|
if (queryName != null) {
|
||||||
|
parseContext.addNamedQuery(queryName, filter);
|
||||||
|
}
|
||||||
|
if (filter != null) {
|
||||||
|
filter.setBoost(boost);
|
||||||
|
}
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.index.query.support.QueryInnerHitBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuilder> implements BoostableQueryBuilder<HasChildQueryBuilder> {
|
public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "has_child";
|
public static final String NAME = "has_child";
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
|
|
||||||
private String childType;
|
private String childType;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String scoreType;
|
private String scoreType;
|
||||||
|
|
||||||
private Integer minChildren;
|
private Integer minChildren;
|
||||||
|
@ -41,8 +39,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
|
|
||||||
private Integer shortCircuitCutoff;
|
private Integer shortCircuitCutoff;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private QueryInnerHitBuilder innerHit = null;
|
private QueryInnerHitBuilder innerHit = null;
|
||||||
|
|
||||||
static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder(null, null);
|
static final HasChildQueryBuilder PROTOTYPE = new HasChildQueryBuilder(null, null);
|
||||||
|
@ -52,16 +48,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
this.queryBuilder = queryBuilder;
|
this.queryBuilder = queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public HasChildQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how the scores from the matching child documents are mapped into the parent document.
|
* Defines how the scores from the matching child documents are mapped into the parent document.
|
||||||
*/
|
*/
|
||||||
|
@ -95,14 +81,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public HasChildQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets inner hit definition in the scope of this query and reusing the defined type and query.
|
* Sets inner hit definition in the scope of this query and reusing the defined type and query.
|
||||||
*/
|
*/
|
||||||
|
@ -117,9 +95,6 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
builder.field("query");
|
builder.field("query");
|
||||||
queryBuilder.toXContent(builder, params);
|
queryBuilder.toXContent(builder, params);
|
||||||
builder.field("child_type", childType);
|
builder.field("child_type", childType);
|
||||||
if (boost != 1.0f) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (scoreType != null) {
|
if (scoreType != null) {
|
||||||
builder.field("score_type", scoreType);
|
builder.field("score_type", scoreType);
|
||||||
}
|
}
|
||||||
|
@ -132,9 +107,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
if (shortCircuitCutoff != null) {
|
if (shortCircuitCutoff != null) {
|
||||||
builder.field("short_circuit_cutoff", shortCircuitCutoff);
|
builder.field("short_circuit_cutoff", shortCircuitCutoff);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (innerHit != null) {
|
if (innerHit != null) {
|
||||||
builder.startObject("inner_hits");
|
builder.startObject("inner_hits");
|
||||||
builder.value(innerHit);
|
builder.value(innerHit);
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class HasChildQueryParser extends BaseQueryParserTemp {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
boolean queryFound = false;
|
boolean queryFound = false;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String childType = null;
|
String childType = null;
|
||||||
ScoreType scoreType = ScoreType.NONE;
|
ScoreType scoreType = ScoreType.NONE;
|
||||||
int minChildren = 0;
|
int minChildren = 0;
|
||||||
|
|
|
@ -26,14 +26,12 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Builder for the 'has_parent' query.
|
* Builder for the 'has_parent' query.
|
||||||
*/
|
*/
|
||||||
public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBuilder> implements BoostableQueryBuilder<HasParentQueryBuilder> {
|
public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "has_parent";
|
public static final String NAME = "has_parent";
|
||||||
private final QueryBuilder queryBuilder;
|
private final QueryBuilder queryBuilder;
|
||||||
private final String parentType;
|
private final String parentType;
|
||||||
private String scoreType;
|
private String scoreType;
|
||||||
private float boost = 1.0f;
|
|
||||||
private String queryName;
|
|
||||||
private QueryInnerHitBuilder innerHit = null;
|
private QueryInnerHitBuilder innerHit = null;
|
||||||
static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder(null, null);
|
static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder(null, null);
|
||||||
|
|
||||||
|
@ -46,12 +44,6 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
||||||
this.queryBuilder = parentQuery;
|
this.queryBuilder = parentQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HasParentQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how the parent score is mapped into the child documents.
|
* Defines how the parent score is mapped into the child documents.
|
||||||
*/
|
*/
|
||||||
|
@ -60,14 +52,6 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public HasParentQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets inner hit definition in the scope of this query and reusing the defined type and query.
|
* Sets inner hit definition in the scope of this query and reusing the defined type and query.
|
||||||
*/
|
*/
|
||||||
|
@ -85,12 +69,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
||||||
if (scoreType != null) {
|
if (scoreType != null) {
|
||||||
builder.field("score_type", scoreType);
|
builder.field("score_type", scoreType);
|
||||||
}
|
}
|
||||||
if (boost != 1.0f) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (innerHit != null) {
|
if (innerHit != null) {
|
||||||
builder.startObject("inner_hits");
|
builder.startObject("inner_hits");
|
||||||
builder.value(innerHit);
|
builder.value(innerHit);
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class HasParentQueryParser extends BaseQueryParserTemp {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
boolean queryFound = false;
|
boolean queryFound = false;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String parentType = null;
|
String parentType = null;
|
||||||
boolean score = false;
|
boolean score = false;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.*;
|
||||||
/**
|
/**
|
||||||
* A query that will return only documents matching specific ids (and a type).
|
* A query that will return only documents matching specific ids (and a type).
|
||||||
*/
|
*/
|
||||||
public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> implements BoostableQueryBuilder<IdsQueryBuilder> {
|
public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "ids";
|
public static final String NAME = "ids";
|
||||||
|
|
||||||
|
@ -46,10 +46,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
|
|
||||||
private final String[] types;
|
private final String[] types;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final IdsQueryBuilder PROTOTYPE = new IdsQueryBuilder();
|
static final IdsQueryBuilder PROTOTYPE = new IdsQueryBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,38 +99,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
return this.ids;
|
return this.ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IdsQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the boost for this query.
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the query that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public IdsQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the query name for the query.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -150,10 +114,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
builder.value(value);
|
builder.value(value);
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
builder.field("boost", boost);
|
printBoostAndQueryName(builder);
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +124,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
Query query;
|
Query query;
|
||||||
if (this.ids.isEmpty()) {
|
if (this.ids.isEmpty()) {
|
||||||
query = Queries.newMatchNoDocsQuery();
|
query = Queries.newMatchNoDocsQuery();
|
||||||
|
@ -179,10 +140,6 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
|
|
||||||
query = new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(typesForQuery, ids));
|
query = new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(typesForQuery, ids));
|
||||||
}
|
}
|
||||||
query.setBoost(boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,32 +150,26 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdsQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected IdsQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
IdsQueryBuilder idsQueryBuilder = new IdsQueryBuilder(in.readStringArray());
|
IdsQueryBuilder idsQueryBuilder = new IdsQueryBuilder(in.readStringArray());
|
||||||
idsQueryBuilder.addIds(in.readStringArray());
|
idsQueryBuilder.addIds(in.readStringArray());
|
||||||
idsQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
idsQueryBuilder.boost = in.readFloat();
|
|
||||||
return idsQueryBuilder;
|
return idsQueryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeStringArray(types);
|
out.writeStringArray(types);
|
||||||
out.writeStringArray(ids.toArray(new String[ids.size()]));
|
out.writeStringArray(ids.toArray(new String[ids.size()]));
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
out.writeFloat(boost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(ids, Arrays.hashCode(types), boost, queryName);
|
return Objects.hash(ids, Arrays.hashCode(types));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(IdsQueryBuilder other) {
|
protected boolean doEquals(IdsQueryBuilder other) {
|
||||||
return Objects.equals(ids, other.ids) &&
|
return Objects.equals(ids, other.ids) &&
|
||||||
Arrays.equals(types, other.types) &&
|
Arrays.equals(types, other.types);
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class IdsQueryParser extends BaseQueryParser {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
List<String> ids = new ArrayList<>();
|
List<String> ids = new ArrayList<>();
|
||||||
List<String> types = new ArrayList<>();
|
List<String> types = new ArrayList<>();
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
|
|
@ -38,8 +38,6 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
||||||
private String sNoMatchQuery;
|
private String sNoMatchQuery;
|
||||||
private QueryBuilder noMatchQuery;
|
private QueryBuilder noMatchQuery;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final IndicesQueryBuilder PROTOTYPE = new IndicesQueryBuilder(null);
|
static final IndicesQueryBuilder PROTOTYPE = new IndicesQueryBuilder(null);
|
||||||
|
|
||||||
public IndicesQueryBuilder(QueryBuilder queryBuilder, String... indices) {
|
public IndicesQueryBuilder(QueryBuilder queryBuilder, String... indices) {
|
||||||
|
@ -63,14 +61,6 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public IndicesQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -83,9 +73,7 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
||||||
} else if (sNoMatchQuery != null) {
|
} else if (sNoMatchQuery != null) {
|
||||||
builder.field("no_match_query", sNoMatchQuery);
|
builder.field("no_match_query", sNoMatchQuery);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class IndicesQueryParser extends BaseQueryParserTemp {
|
||||||
boolean indicesFound = false;
|
boolean indicesFound = false;
|
||||||
boolean currentIndexMatchesIndices = false;
|
boolean currentIndexMatchesIndices = false;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -114,6 +115,8 @@ public class IndicesQueryParser extends BaseQueryParserTemp {
|
||||||
}
|
}
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -145,6 +148,7 @@ public class IndicesQueryParser extends BaseQueryParserTemp {
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, chosenQuery);
|
parseContext.addNamedQuery(queryName, chosenQuery);
|
||||||
}
|
}
|
||||||
|
chosenQuery.setBoost(boost);
|
||||||
return chosenQuery;
|
return chosenQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,12 @@ public class LimitQueryBuilder extends AbstractQueryBuilder<LimitQueryBuilder> {
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field("value", limit);
|
builder.field("value", limit);
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
@ -62,23 +63,22 @@ public class LimitQueryBuilder extends AbstractQueryBuilder<LimitQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(LimitQueryBuilder other) {
|
protected boolean doEquals(LimitQueryBuilder other) {
|
||||||
return Integer.compare(other.limit, limit) == 0;
|
return Integer.compare(other.limit, limit) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return this.limit;
|
return this.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LimitQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected LimitQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
LimitQueryBuilder limitQueryBuilder = new LimitQueryBuilder(in.readInt());
|
return new LimitQueryBuilder(in.readInt());
|
||||||
return limitQueryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeInt(limit);
|
out.writeInt(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class LimitQueryParser extends BaseQueryParser {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
int limit = -1;
|
int limit = -1;
|
||||||
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
@ -49,6 +51,10 @@ public class LimitQueryParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("value".equals(currentFieldName)) {
|
if ("value".equals(currentFieldName)) {
|
||||||
limit = parser.intValue();
|
limit = parser.intValue();
|
||||||
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[limit] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[limit] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -59,7 +65,7 @@ public class LimitQueryParser extends BaseQueryParser {
|
||||||
throw new QueryParsingException(parseContext, "No value specified for limit query");
|
throw new QueryParsingException(parseContext, "No value specified for limit query");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LimitQueryBuilder(limit);
|
return new LimitQueryBuilder(limit).boost(boost).queryName(queryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
@ -31,48 +30,22 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* A query that matches on all documents.
|
* A query that matches on all documents.
|
||||||
*/
|
*/
|
||||||
public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuilder> implements BoostableQueryBuilder<MatchAllQueryBuilder> {
|
public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "match_all";
|
public static final String NAME = "match_all";
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
static final MatchAllQueryBuilder PROTOTYPE = new MatchAllQueryBuilder();
|
static final MatchAllQueryBuilder PROTOTYPE = new MatchAllQueryBuilder();
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public MatchAllQueryBuilder boost(float boost) {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the boost for this query.
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
if (boost != 1.0f) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
if (this.boost == 1.0f) {
|
return Queries.newMatchAllQuery();
|
||||||
return Queries.newMatchAllQuery();
|
|
||||||
}
|
|
||||||
MatchAllDocsQuery query = new MatchAllDocsQuery();
|
|
||||||
query.setBoost(boost);
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,25 +55,23 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(MatchAllQueryBuilder other) {
|
protected boolean doEquals(MatchAllQueryBuilder other) {
|
||||||
return Float.compare(other.boost, boost) == 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return boost != +0.0f ? Float.floatToIntBits(boost) : 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MatchAllQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected MatchAllQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
MatchAllQueryBuilder matchAllQueryBuilder = new MatchAllQueryBuilder();
|
return new MatchAllQueryBuilder();
|
||||||
matchAllQueryBuilder.boost = in.readFloat();
|
|
||||||
return matchAllQueryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeFloat(this.boost);
|
//nothing to write really
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,12 +45,15 @@ public class MatchAllQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
float boost = 1.0f;
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
|
while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("boost".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
boost = parser.floatValue();
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[match_all] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[match_all] query does not support [" + currentFieldName + "]");
|
||||||
|
@ -59,6 +62,7 @@ public class MatchAllQueryParser extends BaseQueryParser {
|
||||||
}
|
}
|
||||||
MatchAllQueryBuilder queryBuilder = new MatchAllQueryBuilder();
|
MatchAllQueryBuilder queryBuilder = new MatchAllQueryBuilder();
|
||||||
queryBuilder.boost(boost);
|
queryBuilder.boost(boost);
|
||||||
|
queryBuilder.queryName(queryName);
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Locale;
|
||||||
* Match query is a query that analyzes the text and constructs a query as the result of the analysis. It
|
* Match query is a query that analyzes the text and constructs a query as the result of the analysis. It
|
||||||
* can construct different queries based on the type provided.
|
* can construct different queries based on the type provided.
|
||||||
*/
|
*/
|
||||||
public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> implements BoostableQueryBuilder<MatchQueryBuilder> {
|
public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "match";
|
public static final String NAME = "match";
|
||||||
|
|
||||||
|
@ -63,8 +63,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
|
|
||||||
private String analyzer;
|
private String analyzer;
|
||||||
|
|
||||||
private Float boost;
|
|
||||||
|
|
||||||
private Integer slop;
|
private Integer slop;
|
||||||
|
|
||||||
private Fuzziness fuzziness;
|
private Fuzziness fuzziness;
|
||||||
|
@ -87,8 +85,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
|
|
||||||
private Float cutoff_Frequency = null;
|
private Float cutoff_Frequency = null;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final MatchQueryBuilder PROTOTYPE = new MatchQueryBuilder(null, null);
|
static final MatchQueryBuilder PROTOTYPE = new MatchQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,15 +120,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the boost to apply to the query.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public MatchQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the phrase slop if evaluated to a phrase query type.
|
* Set the phrase slop if evaluated to a phrase query type.
|
||||||
*/
|
*/
|
||||||
|
@ -207,14 +194,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public MatchQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -230,9 +209,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
if (analyzer != null) {
|
if (analyzer != null) {
|
||||||
builder.field("analyzer", analyzer);
|
builder.field("analyzer", analyzer);
|
||||||
}
|
}
|
||||||
if (boost != null) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (slop != null) {
|
if (slop != null) {
|
||||||
builder.field("slop", slop);
|
builder.field("slop", slop);
|
||||||
}
|
}
|
||||||
|
@ -267,11 +243,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> i
|
||||||
if (cutoff_Frequency != null) {
|
if (cutoff_Frequency != null) {
|
||||||
builder.field("cutoff_frequency", cutoff_Frequency);
|
builder.field("cutoff_frequency", cutoff_Frequency);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class MatchQueryParser extends BaseQueryParserTemp {
|
||||||
String fieldName = parser.currentName();
|
String fieldName = parser.currentName();
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
MatchQuery matchQuery = new MatchQuery(parseContext);
|
MatchQuery matchQuery = new MatchQuery(parseContext);
|
||||||
String minimumShouldMatch = null;
|
String minimumShouldMatch = null;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
|
@ -32,8 +32,6 @@ public class MissingQueryBuilder extends AbstractQueryBuilder<MissingQueryBuilde
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private Boolean nullValue;
|
private Boolean nullValue;
|
||||||
|
|
||||||
private Boolean existence;
|
private Boolean existence;
|
||||||
|
@ -62,14 +60,6 @@ public class MissingQueryBuilder extends AbstractQueryBuilder<MissingQueryBuilde
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public MissingQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -80,9 +70,7 @@ public class MissingQueryBuilder extends AbstractQueryBuilder<MissingQueryBuilde
|
||||||
if (existence != null) {
|
if (existence != null) {
|
||||||
builder.field("existence", existence);
|
builder.field("existence", existence);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ public class MissingQueryParser extends BaseQueryParserTemp {
|
||||||
|
|
||||||
String fieldPattern = null;
|
String fieldPattern = null;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
boolean nullValue = DEFAULT_NULL_VALUE;
|
boolean nullValue = DEFAULT_NULL_VALUE;
|
||||||
boolean existence = DEFAULT_EXISTENCE_VALUE;
|
boolean existence = DEFAULT_EXISTENCE_VALUE;
|
||||||
|
|
||||||
|
@ -74,6 +75,8 @@ public class MissingQueryParser extends BaseQueryParserTemp {
|
||||||
existence = parser.booleanValue();
|
existence = parser.booleanValue();
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[missing] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[missing] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -83,11 +86,17 @@ public class MissingQueryParser extends BaseQueryParserTemp {
|
||||||
if (fieldPattern == null) {
|
if (fieldPattern == null) {
|
||||||
throw new QueryParsingException(parseContext, "missing must be provided with a [field]");
|
throw new QueryParsingException(parseContext, "missing must be provided with a [field]");
|
||||||
}
|
}
|
||||||
|
Query query = newFilter(parseContext, fieldPattern, existence, nullValue);
|
||||||
return newFilter(parseContext, fieldPattern, existence, nullValue, queryName);
|
if (queryName != null) {
|
||||||
|
parseContext.addNamedQuery(queryName, query);
|
||||||
|
}
|
||||||
|
if (query != null) {
|
||||||
|
query.setBoost(boost);
|
||||||
|
}
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, boolean existence, boolean nullValue, String queryName) {
|
public static Query newFilter(QueryParseContext parseContext, String fieldPattern, boolean existence, boolean nullValue) {
|
||||||
if (!existence && !nullValue) {
|
if (!existence && !nullValue) {
|
||||||
throw new QueryParsingException(parseContext, "missing must have either existence, or null_value, or both set to true");
|
throw new QueryParsingException(parseContext, "missing must have either existence, or null_value, or both set to true");
|
||||||
}
|
}
|
||||||
|
@ -172,9 +181,6 @@ public class MissingQueryParser extends BaseQueryParserTemp {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, existenceFilter);
|
|
||||||
}
|
|
||||||
return new ConstantScoreQuery(filter);
|
return new ConstantScoreQuery(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ import java.util.Locale;
|
||||||
* A more like this query that finds documents that are "like" the provided {@link #likeText(String)}
|
* A more like this query that finds documents that are "like" the provided {@link #likeText(String)}
|
||||||
* which is checked against the fields the query is constructed with.
|
* which is checked against the fields the query is constructed with.
|
||||||
*/
|
*/
|
||||||
public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQueryBuilder> implements BoostableQueryBuilder<MoreLikeThisQueryBuilder> {
|
public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQueryBuilder> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single get item. Pure delegate to multi get.
|
* A single get item. Pure delegate to multi get.
|
||||||
|
@ -147,10 +147,8 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
||||||
private int minWordLength = -1;
|
private int minWordLength = -1;
|
||||||
private int maxWordLength = -1;
|
private int maxWordLength = -1;
|
||||||
private float boostTerms = -1;
|
private float boostTerms = -1;
|
||||||
private float boost = -1;
|
|
||||||
private String analyzer;
|
private String analyzer;
|
||||||
private Boolean failOnUnsupportedField;
|
private Boolean failOnUnsupportedField;
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final MoreLikeThisQueryBuilder PROTOTYPE = new MoreLikeThisQueryBuilder();
|
static final MoreLikeThisQueryBuilder PROTOTYPE = new MoreLikeThisQueryBuilder();
|
||||||
|
|
||||||
|
@ -348,12 +346,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MoreLikeThisQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to fail or return no result when this query is run against a field which is not supported such as binary/numeric fields.
|
* Whether to fail or return no result when this query is run against a field which is not supported such as binary/numeric fields.
|
||||||
*/
|
*/
|
||||||
|
@ -362,14 +354,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public MoreLikeThisQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
String likeFieldName = MoreLikeThisQueryParser.Fields.LIKE.getPreferredName();
|
String likeFieldName = MoreLikeThisQueryParser.Fields.LIKE.getPreferredName();
|
||||||
|
@ -420,21 +404,16 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
||||||
if (boostTerms != -1) {
|
if (boostTerms != -1) {
|
||||||
builder.field(MoreLikeThisQueryParser.Fields.BOOST_TERMS.getPreferredName(), boostTerms);
|
builder.field(MoreLikeThisQueryParser.Fields.BOOST_TERMS.getPreferredName(), boostTerms);
|
||||||
}
|
}
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (analyzer != null) {
|
if (analyzer != null) {
|
||||||
builder.field("analyzer", analyzer);
|
builder.field("analyzer", analyzer);
|
||||||
}
|
}
|
||||||
if (failOnUnsupportedField != null) {
|
if (failOnUnsupportedField != null) {
|
||||||
builder.field(MoreLikeThisQueryParser.Fields.FAIL_ON_UNSUPPORTED_FIELD.getPreferredName(), failOnUnsupportedField);
|
builder.field(MoreLikeThisQueryParser.Fields.FAIL_ON_UNSUPPORTED_FIELD.getPreferredName(), failOnUnsupportedField);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (include != null) {
|
if (include != null) {
|
||||||
builder.field("include", include);
|
builder.field("include", include);
|
||||||
}
|
}
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Same as {@link MatchQueryBuilder} but supports multiple fields.
|
* Same as {@link MatchQueryBuilder} but supports multiple fields.
|
||||||
*/
|
*/
|
||||||
public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQueryBuilder> implements BoostableQueryBuilder<MultiMatchQueryBuilder> {
|
public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "multi_match";
|
public static final String NAME = "multi_match";
|
||||||
|
|
||||||
|
@ -52,8 +52,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
|
|
||||||
private String analyzer;
|
private String analyzer;
|
||||||
|
|
||||||
private Float boost;
|
|
||||||
|
|
||||||
private Integer slop;
|
private Integer slop;
|
||||||
|
|
||||||
private Fuzziness fuzziness;
|
private Fuzziness fuzziness;
|
||||||
|
@ -78,8 +76,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
|
|
||||||
private MatchQueryBuilder.ZeroTermsQuery zeroTermsQuery = null;
|
private MatchQueryBuilder.ZeroTermsQuery zeroTermsQuery = null;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final MultiMatchQueryBuilder PROTOTYPE = new MultiMatchQueryBuilder(null);
|
static final MultiMatchQueryBuilder PROTOTYPE = new MultiMatchQueryBuilder(null);
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
|
@ -219,15 +215,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the boost to apply to the query.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public MultiMatchQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the phrase slop if evaluated to a phrase query type.
|
* Set the phrase slop if evaluated to a phrase query type.
|
||||||
*/
|
*/
|
||||||
|
@ -325,14 +312,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public MultiMatchQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -357,9 +336,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
if (analyzer != null) {
|
if (analyzer != null) {
|
||||||
builder.field("analyzer", analyzer);
|
builder.field("analyzer", analyzer);
|
||||||
}
|
}
|
||||||
if (boost != null) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (slop != null) {
|
if (slop != null) {
|
||||||
builder.field("slop", slop);
|
builder.field("slop", slop);
|
||||||
}
|
}
|
||||||
|
@ -402,9 +378,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
builder.field("zero_terms_query", zeroTermsQuery.toString());
|
builder.field("zero_terms_query", zeroTermsQuery.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class MultiMatchQueryParser extends BaseQueryParserTemp {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
Float tieBreaker = null;
|
Float tieBreaker = null;
|
||||||
MultiMatchQueryBuilder.Type type = null;
|
MultiMatchQueryBuilder.Type type = null;
|
||||||
MultiMatchQuery multiMatchQuery = new MultiMatchQuery(parseContext);
|
MultiMatchQuery multiMatchQuery = new MultiMatchQuery(parseContext);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.index.query.support.QueryInnerHitBuilder;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder> implements BoostableQueryBuilder<NestedQueryBuilder> {
|
public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "nested";
|
public static final String NAME = "nested";
|
||||||
|
|
||||||
|
@ -35,10 +35,6 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
||||||
|
|
||||||
private String scoreMode;
|
private String scoreMode;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private QueryInnerHitBuilder innerHit;
|
private QueryInnerHitBuilder innerHit;
|
||||||
|
|
||||||
static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder();
|
static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder();
|
||||||
|
@ -64,24 +60,6 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public NestedQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public NestedQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets inner hit definition in the scope of this nested query and reusing the defined path and query.
|
* Sets inner hit definition in the scope of this nested query and reusing the defined path and query.
|
||||||
*/
|
*/
|
||||||
|
@ -99,12 +77,7 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
||||||
if (scoreMode != null) {
|
if (scoreMode != null) {
|
||||||
builder.field("score_mode", scoreMode);
|
builder.field("score_mode", scoreMode);
|
||||||
}
|
}
|
||||||
if (boost != 1.0f) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (innerHit != null) {
|
if (innerHit != null) {
|
||||||
builder.startObject("inner_hits");
|
builder.startObject("inner_hits");
|
||||||
builder.value(innerHit);
|
builder.value(innerHit);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class NestedQueryParser extends BaseQueryParserTemp {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
final ToBlockJoinQueryBuilder builder = new ToBlockJoinQueryBuilder(parseContext);
|
final ToBlockJoinQueryBuilder builder = new ToBlockJoinQueryBuilder(parseContext);
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
ScoreMode scoreMode = ScoreMode.Avg;
|
ScoreMode scoreMode = ScoreMode.Avg;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ public class NotQueryBuilder extends AbstractQueryBuilder<NotQueryBuilder> {
|
||||||
|
|
||||||
private final QueryBuilder filter;
|
private final QueryBuilder filter;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final NotQueryBuilder PROTOTYPE = new NotQueryBuilder(null);
|
static final NotQueryBuilder PROTOTYPE = new NotQueryBuilder(null);
|
||||||
|
|
||||||
public NotQueryBuilder(QueryBuilder filter) {
|
public NotQueryBuilder(QueryBuilder filter) {
|
||||||
|
@ -52,47 +50,24 @@ public class NotQueryBuilder extends AbstractQueryBuilder<NotQueryBuilder> {
|
||||||
return this.filter;
|
return this.filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public NotQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
doXContentInnerBuilder(builder, "query", filter, params);
|
doXContentInnerBuilder(builder, "query", filter, params);
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Query luceneQuery = filter.toQuery(parseContext);
|
Query luceneQuery = filter.toQuery(parseContext);
|
||||||
if (luceneQuery == null) {
|
if (luceneQuery == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return Queries.not(luceneQuery);
|
||||||
Query notQuery = Queries.not(luceneQuery);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, notQuery);
|
|
||||||
}
|
|
||||||
return notQuery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,28 +76,24 @@ public class NotQueryBuilder extends AbstractQueryBuilder<NotQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(filter, queryName);
|
return Objects.hash(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(NotQueryBuilder other) {
|
protected boolean doEquals(NotQueryBuilder other) {
|
||||||
return Objects.equals(filter, other.filter) &&
|
return Objects.equals(filter, other.filter);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NotQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected NotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder queryBuilder = in.readNamedWriteable();
|
QueryBuilder queryBuilder = in.readNamedWriteable();
|
||||||
NotQueryBuilder notQueryBuilder = new NotQueryBuilder(queryBuilder);
|
return new NotQueryBuilder(queryBuilder);
|
||||||
notQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
return notQueryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(filter);
|
out.writeNamedWriteable(filter);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class NotQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
@ -72,6 +73,8 @@ public class NotQueryParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[not] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[not] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -84,6 +87,7 @@ public class NotQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
NotQueryBuilder notQueryBuilder = new NotQueryBuilder(query);
|
NotQueryBuilder notQueryBuilder = new NotQueryBuilder(query);
|
||||||
notQueryBuilder.queryName(queryName);
|
notQueryBuilder.queryName(queryName);
|
||||||
|
notQueryBuilder.boost(boost);
|
||||||
return notQueryBuilder;
|
return notQueryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
|
|
||||||
private final ArrayList<QueryBuilder> filters = Lists.newArrayList();
|
private final ArrayList<QueryBuilder> filters = Lists.newArrayList();
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final OrQueryBuilder PROTOTYPE = new OrQueryBuilder();
|
static final OrQueryBuilder PROTOTYPE = new OrQueryBuilder();
|
||||||
|
|
||||||
public OrQueryBuilder(QueryBuilder... filters) {
|
public OrQueryBuilder(QueryBuilder... filters) {
|
||||||
|
@ -70,21 +68,6 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
return this.filters;
|
return this.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public OrQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the query name.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -93,14 +76,12 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
filter.toXContent(builder, params);
|
filter.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
if (filters.isEmpty()) {
|
if (filters.isEmpty()) {
|
||||||
// no filters provided, this should be ignored upstream
|
// no filters provided, this should be ignored upstream
|
||||||
return null;
|
return null;
|
||||||
|
@ -114,9 +95,6 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
query.add(innerQuery, Occur.SHOULD);
|
query.add(innerQuery, Occur.SHOULD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,31 +109,28 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(filters, queryName);
|
return Objects.hash(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(OrQueryBuilder other) {
|
protected boolean doEquals(OrQueryBuilder other) {
|
||||||
return Objects.equals(filters, other.filters) &&
|
return Objects.equals(filters, other.filters);
|
||||||
Objects.equals(queryName, other.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected OrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
OrQueryBuilder orQueryBuilder = new OrQueryBuilder();
|
OrQueryBuilder orQueryBuilder = new OrQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
||||||
for (QueryBuilder queryBuilder : queryBuilders) {
|
for (QueryBuilder queryBuilder : queryBuilders) {
|
||||||
orQueryBuilder.add(queryBuilder);
|
orQueryBuilder.add(queryBuilder);
|
||||||
}
|
}
|
||||||
orQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
return orQueryBuilder;
|
return orQueryBuilder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(filters);
|
out.writeNamedWriteableList(filters);
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class OrQueryParser extends BaseQueryParser {
|
||||||
final ArrayList<QueryBuilder> queries = newArrayList();
|
final ArrayList<QueryBuilder> queries = newArrayList();
|
||||||
boolean queriesFound = false;
|
boolean queriesFound = false;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token = parser.currentToken();
|
XContentParser.Token token = parser.currentToken();
|
||||||
|
@ -82,6 +83,8 @@ public class OrQueryParser extends BaseQueryParser {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[or] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[or] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -98,6 +101,7 @@ public class OrQueryParser extends BaseQueryParser {
|
||||||
orQuery.add(query);
|
orQuery.add(query);
|
||||||
}
|
}
|
||||||
orQuery.queryName(queryName);
|
orQuery.queryName(queryName);
|
||||||
|
orQuery.boost(boost);
|
||||||
return orQuery;
|
return orQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* A Query that matches documents containing terms with a specified prefix.
|
* A Query that matches documents containing terms with a specified prefix.
|
||||||
*/
|
*/
|
||||||
public class PrefixQueryBuilder extends MultiTermQueryBuilder implements BoostableQueryBuilder<PrefixQueryBuilder> {
|
public class PrefixQueryBuilder extends MultiTermQueryBuilder {
|
||||||
|
|
||||||
public static final String NAME = "prefix";
|
public static final String NAME = "prefix";
|
||||||
|
|
||||||
|
@ -34,12 +34,8 @@ public class PrefixQueryBuilder extends MultiTermQueryBuilder implements Boostab
|
||||||
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String rewrite;
|
private String rewrite;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final PrefixQueryBuilder PROTOTYPE = new PrefixQueryBuilder(null, null);
|
static final PrefixQueryBuilder PROTOTYPE = new PrefixQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,48 +49,21 @@ public class PrefixQueryBuilder extends MultiTermQueryBuilder implements Boostab
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PrefixQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrefixQueryBuilder rewrite(String rewrite) {
|
public PrefixQueryBuilder rewrite(String rewrite) {
|
||||||
this.rewrite = rewrite;
|
this.rewrite = rewrite;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public PrefixQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
if (boost == -1 && rewrite == null && queryName == null) {
|
builder.startObject(name);
|
||||||
builder.field(name, prefix);
|
builder.field("prefix", prefix);
|
||||||
} else {
|
if (rewrite != null) {
|
||||||
builder.startObject(name);
|
builder.field("rewrite", rewrite);
|
||||||
builder.field("prefix", prefix);
|
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (rewrite != null) {
|
|
||||||
builder.field("rewrite", rewrite);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class PrefixQueryParser extends BaseQueryParserTemp {
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public interface QueryBuilder<QB extends QueryBuilder> extends NamedWriteable<QB
|
||||||
* @throws QueryParsingException
|
* @throws QueryParsingException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException;
|
Query toQuery(QueryParseContext parseContext) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link org.elasticsearch.common.bytes.BytesReference}
|
* Returns a {@link org.elasticsearch.common.bytes.BytesReference}
|
||||||
|
|
|
@ -58,13 +58,25 @@ public class QueryFilterBuilder extends AbstractQueryBuilder<QueryFilterBuilder>
|
||||||
return this.queryBuilder;
|
return this.queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryFilterBuilder boost(float boost) {
|
||||||
|
//no-op: QueryFilterParser doesn't support boost, we should be consistent and ignore it here too.
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryFilterBuilder queryName(String queryName) {
|
||||||
|
//no-op: QueryFilterParser doesn't support _name, we should be consistent and ignore it here too.
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
doXContentInnerBuilder(builder, NAME, queryBuilder, params);
|
doXContentInnerBuilder(builder, NAME, queryBuilder, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// inner query builder can potentially be `null`, in that case we ignore it
|
// inner query builder can potentially be `null`, in that case we ignore it
|
||||||
if (this.queryBuilder == null) {
|
if (this.queryBuilder == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -82,23 +94,23 @@ public class QueryFilterBuilder extends AbstractQueryBuilder<QueryFilterBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(queryBuilder);
|
return Objects.hash(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(QueryFilterBuilder other) {
|
protected boolean doEquals(QueryFilterBuilder other) {
|
||||||
return Objects.equals(queryBuilder, other.queryBuilder);
|
return Objects.equals(queryBuilder, other.queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryFilterBuilder readFrom(StreamInput in) throws IOException {
|
protected QueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
||||||
return new QueryFilterBuilder(innerQueryBuilder);
|
return new QueryFilterBuilder(innerQueryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeNamedWriteable(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import static com.google.common.collect.Lists.newArrayList;
|
||||||
* them either using DisMax or a plain boolean query (see {@link #useDisMax(boolean)}).
|
* them either using DisMax or a plain boolean query (see {@link #useDisMax(boolean)}).
|
||||||
* <p/>
|
* <p/>
|
||||||
*/
|
*/
|
||||||
public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQueryBuilder> implements BoostableQueryBuilder<QueryStringQueryBuilder> {
|
public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "query_string";
|
public static final String NAME = "query_string";
|
||||||
|
|
||||||
|
@ -65,9 +65,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
|
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private Fuzziness fuzziness;
|
private Fuzziness fuzziness;
|
||||||
private int fuzzyPrefixLength = -1;
|
private int fuzzyPrefixLength = -1;
|
||||||
private int fuzzyMaxExpansions = -1;
|
private int fuzzyMaxExpansions = -1;
|
||||||
|
@ -89,8 +86,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
|
|
||||||
private Boolean lenient;
|
private Boolean lenient;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private String timeZone;
|
private String timeZone;
|
||||||
|
|
||||||
/** To limit effort spent determinizing regexp queries. */
|
/** To limit effort spent determinizing regexp queries. */
|
||||||
|
@ -293,16 +288,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public QueryStringQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An optional field name suffix to automatically try and add to the field searched when using quoted text.
|
* An optional field name suffix to automatically try and add to the field searched when using quoted text.
|
||||||
*/
|
*/
|
||||||
|
@ -320,14 +305,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public QueryStringQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueryStringQueryBuilder locale(Locale locale) {
|
public QueryStringQueryBuilder locale(Locale locale) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
return this;
|
return this;
|
||||||
|
@ -391,9 +368,6 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
if (fuzziness != null) {
|
if (fuzziness != null) {
|
||||||
fuzziness.toXContent(builder, params);
|
fuzziness.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (fuzzyPrefixLength != -1) {
|
if (fuzzyPrefixLength != -1) {
|
||||||
builder.field("fuzzy_prefix_length", fuzzyPrefixLength);
|
builder.field("fuzzy_prefix_length", fuzzyPrefixLength);
|
||||||
}
|
}
|
||||||
|
@ -421,15 +395,13 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
if (lenient != null) {
|
if (lenient != null) {
|
||||||
builder.field("lenient", lenient);
|
builder.field("lenient", lenient);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
builder.field("locale", locale.toString());
|
builder.field("locale", locale.toString());
|
||||||
}
|
}
|
||||||
if (timeZone != null) {
|
if (timeZone != null) {
|
||||||
builder.field("time_zone", timeZone);
|
builder.field("time_zone", timeZone);
|
||||||
}
|
}
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,16 +25,20 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QueryBuilder implementation that holds a lucene query, which can be returned by {@link #toQuery(QueryParseContext)}.
|
* QueryBuilder implementation that holds a lucene query, which can be returned by {@link QueryBuilder#toQuery(QueryParseContext)}.
|
||||||
* Doesn't support conversion to {@link org.elasticsearch.common.xcontent.XContent} via {@link #doXContent(XContentBuilder, Params)}.
|
* Doesn't support conversion to {@link org.elasticsearch.common.xcontent.XContent} via {@link #doXContent(XContentBuilder, Params)}.
|
||||||
*/
|
*/
|
||||||
//norelease to be removed once all queries support separate fromXContent and toQuery methods
|
//norelease to be removed once all queries support separate fromXContent and toQuery methods. Make AbstractQueryBuilder#toQuery final as well then.
|
||||||
public class QueryWrappingQueryBuilder extends AbstractQueryBuilder<QueryWrappingQueryBuilder> {
|
public class QueryWrappingQueryBuilder extends AbstractQueryBuilder<QueryWrappingQueryBuilder> {
|
||||||
|
|
||||||
private Query query;
|
private Query query;
|
||||||
|
|
||||||
public QueryWrappingQueryBuilder(Query query) {
|
public QueryWrappingQueryBuilder(Query query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
|
//hack to make sure that the boost from the wrapped query is used, otherwise it gets overwritten.
|
||||||
|
if (query != null) {
|
||||||
|
this.boost = query.getBoost();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,8 +47,8 @@ public class QueryWrappingQueryBuilder extends AbstractQueryBuilder<QueryWrappin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
return this.query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.Objects;
|
||||||
/**
|
/**
|
||||||
* A Query that matches documents within an range of terms.
|
* A Query that matches documents within an range of terms.
|
||||||
*/
|
*/
|
||||||
public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder> implements BoostableQueryBuilder<RangeQueryBuilder> {
|
public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder> {
|
||||||
|
|
||||||
public static final boolean DEFAULT_INCLUDE_UPPER = true;
|
public static final boolean DEFAULT_INCLUDE_UPPER = true;
|
||||||
|
|
||||||
|
@ -58,10 +58,6 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
|
|
||||||
private boolean includeUpper = DEFAULT_INCLUDE_UPPER;
|
private boolean includeUpper = DEFAULT_INCLUDE_UPPER;
|
||||||
|
|
||||||
private float boost = 1.0f;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
static final RangeQueryBuilder PROTOTYPE = new RangeQueryBuilder(null);
|
static final RangeQueryBuilder PROTOTYPE = new RangeQueryBuilder(null);
|
||||||
|
@ -192,38 +188,6 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
return this.includeUpper;
|
return this.includeUpper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public RangeQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the boost factor for the query.
|
|
||||||
*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public RangeQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the query name for the query.
|
|
||||||
*/
|
|
||||||
public String queryName() {
|
|
||||||
return this.queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In case of date field, we can adjust the from/to fields using a timezone
|
* In case of date field, we can adjust the from/to fields using a timezone
|
||||||
*/
|
*/
|
||||||
|
@ -262,17 +226,14 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
builder.field("to", convertToStringIfBytesRef(this.to));
|
builder.field("to", convertToStringIfBytesRef(this.to));
|
||||||
builder.field("include_lower", includeLower);
|
builder.field("include_lower", includeLower);
|
||||||
builder.field("include_upper", includeUpper);
|
builder.field("include_upper", includeUpper);
|
||||||
builder.field("boost", boost);
|
|
||||||
if (timeZone != null) {
|
if (timeZone != null) {
|
||||||
builder.field("time_zone", timeZone);
|
builder.field("time_zone", timeZone);
|
||||||
}
|
}
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
builder.field("format", format);
|
builder.field("format", format);
|
||||||
}
|
}
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +243,7 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
Query query = null;
|
Query query = null;
|
||||||
MappedFieldType mapper = parseContext.fieldMapper(this.fieldName);
|
MappedFieldType mapper = parseContext.fieldMapper(this.fieldName);
|
||||||
if (mapper != null) {
|
if (mapper != null) {
|
||||||
|
@ -314,11 +275,6 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
query = new TermRangeQuery(this.fieldName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper);
|
query = new TermRangeQuery(this.fieldName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper);
|
||||||
}
|
}
|
||||||
|
|
||||||
query.setBoost(boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +304,7 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RangeQueryBuilder readFrom(StreamInput in) throws IOException {
|
protected RangeQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(in.readString());
|
RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(in.readString());
|
||||||
rangeQueryBuilder.from = in.readGenericValue();
|
rangeQueryBuilder.from = in.readGenericValue();
|
||||||
rangeQueryBuilder.to = in.readGenericValue();
|
rangeQueryBuilder.to = in.readGenericValue();
|
||||||
|
@ -356,13 +312,11 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
rangeQueryBuilder.includeUpper = in.readBoolean();
|
rangeQueryBuilder.includeUpper = in.readBoolean();
|
||||||
rangeQueryBuilder.timeZone = in.readOptionalString();
|
rangeQueryBuilder.timeZone = in.readOptionalString();
|
||||||
rangeQueryBuilder.format = in.readOptionalString();
|
rangeQueryBuilder.format = in.readOptionalString();
|
||||||
rangeQueryBuilder.boost = in.readFloat();
|
|
||||||
rangeQueryBuilder.queryName = in.readOptionalString();
|
|
||||||
return rangeQueryBuilder;
|
return rangeQueryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(this.fieldName);
|
out.writeString(this.fieldName);
|
||||||
out.writeGenericValue(this.from);
|
out.writeGenericValue(this.from);
|
||||||
out.writeGenericValue(this.to);
|
out.writeGenericValue(this.to);
|
||||||
|
@ -370,26 +324,21 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
||||||
out.writeBoolean(this.includeUpper);
|
out.writeBoolean(this.includeUpper);
|
||||||
out.writeOptionalString(this.timeZone);
|
out.writeOptionalString(this.timeZone);
|
||||||
out.writeOptionalString(this.format);
|
out.writeOptionalString(this.format);
|
||||||
out.writeFloat(this.boost);
|
|
||||||
out.writeOptionalString(this.queryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(fieldName, from, to, timeZone, includeLower, includeUpper,
|
return Objects.hash(fieldName, from, to, timeZone, includeLower, includeUpper, format);
|
||||||
boost, queryName, format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(RangeQueryBuilder other) {
|
protected boolean doEquals(RangeQueryBuilder other) {
|
||||||
return Objects.equals(fieldName, other.fieldName) &&
|
return Objects.equals(fieldName, other.fieldName) &&
|
||||||
Objects.equals(from, other.from) &&
|
Objects.equals(from, other.from) &&
|
||||||
Objects.equals(to, other.to) &&
|
Objects.equals(to, other.to) &&
|
||||||
Objects.equals(timeZone, other.timeZone) &&
|
Objects.equals(timeZone, other.timeZone) &&
|
||||||
Objects.equals(includeLower, other.includeLower) &&
|
Objects.equals(includeLower, other.includeLower) &&
|
||||||
Objects.equals(includeUpper, other.includeUpper) &&
|
Objects.equals(includeUpper, other.includeUpper) &&
|
||||||
Objects.equals(boost, other.boost) &&
|
|
||||||
Objects.equals(queryName, other.queryName) &&
|
|
||||||
Objects.equals(format, other.format);
|
Objects.equals(format, other.format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class RangeQueryParser extends BaseQueryParser {
|
||||||
boolean includeLower = RangeQueryBuilder.DEFAULT_INCLUDE_LOWER;
|
boolean includeLower = RangeQueryBuilder.DEFAULT_INCLUDE_LOWER;
|
||||||
boolean includeUpper = RangeQueryBuilder.DEFAULT_INCLUDE_UPPER;
|
boolean includeUpper = RangeQueryBuilder.DEFAULT_INCLUDE_UPPER;
|
||||||
String timeZone = null;
|
String timeZone = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String format = null;
|
String format = null;
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ public class RangeQueryParser extends BaseQueryParser {
|
||||||
timeZone = parser.text();
|
timeZone = parser.text();
|
||||||
} else if ("format".equals(currentFieldName)) {
|
} else if ("format".equals(currentFieldName)) {
|
||||||
format = parser.text();
|
format = parser.text();
|
||||||
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext, "[range] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[range] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,16 +27,14 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* A Query that does fuzzy matching for a specific value.
|
* A Query that does fuzzy matching for a specific value.
|
||||||
*/
|
*/
|
||||||
public class RegexpQueryBuilder extends MultiTermQueryBuilder implements BoostableQueryBuilder<RegexpQueryBuilder> {
|
public class RegexpQueryBuilder extends MultiTermQueryBuilder {
|
||||||
|
|
||||||
public static final String NAME = "regexp";
|
public static final String NAME = "regexp";
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String regexp;
|
private final String regexp;
|
||||||
|
|
||||||
private int flags = -1;
|
private int flags = -1;
|
||||||
private float boost = -1;
|
|
||||||
private String rewrite;
|
private String rewrite;
|
||||||
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);
|
static final RegexpQueryBuilder PROTOTYPE = new RegexpQueryBuilder(null, null);
|
||||||
|
@ -52,16 +50,6 @@ public class RegexpQueryBuilder extends MultiTermQueryBuilder implements Boostab
|
||||||
this.regexp = regexp;
|
this.regexp = regexp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public RegexpQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegexpQueryBuilder flags(RegexpFlag... flags) {
|
public RegexpQueryBuilder flags(RegexpFlag... flags) {
|
||||||
int value = 0;
|
int value = 0;
|
||||||
if (flags.length == 0) {
|
if (flags.length == 0) {
|
||||||
|
@ -89,14 +77,6 @@ public class RegexpQueryBuilder extends MultiTermQueryBuilder implements Boostab
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public RegexpQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -108,15 +88,10 @@ public class RegexpQueryBuilder extends MultiTermQueryBuilder implements Boostab
|
||||||
if (maxDetermizedStatesSet) {
|
if (maxDetermizedStatesSet) {
|
||||||
builder.field("max_determinized_states", maxDeterminizedStates);
|
builder.field("max_determinized_states", maxDeterminizedStates);
|
||||||
}
|
}
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (rewrite != null) {
|
if (rewrite != null) {
|
||||||
builder.field("rewrite", rewrite);
|
builder.field("rewrite", rewrite);
|
||||||
}
|
}
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class RegexpQueryParser extends BaseQueryParserTemp {
|
||||||
String rewriteMethod = null;
|
String rewriteMethod = null;
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
int flagsValue = -1;
|
int flagsValue = -1;
|
||||||
int maxDeterminizedStates = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
|
int maxDeterminizedStates = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
|
@ -33,27 +33,15 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||||
|
|
||||||
private Script script;
|
private Script script;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
public ScriptQueryBuilder(Script script) {
|
public ScriptQueryBuilder(Script script) {
|
||||||
this.script = script;
|
this.script = script;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public ScriptQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params builderParams) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
builder.field(ScriptField.SCRIPT.getPreferredName(), script);
|
||||||
if (queryName != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class ScriptQueryParser extends BaseQueryParserTemp {
|
||||||
Script script = null;
|
Script script = null;
|
||||||
Map<String, Object> params = null;
|
Map<String, Object> params = null;
|
||||||
|
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
|
||||||
|
@ -88,6 +89,8 @@ public class ScriptQueryParser extends BaseQueryParserTemp {
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
} else if (!scriptParameterParser.token(currentFieldName, token, parser)) {
|
} else if (!scriptParameterParser.token(currentFieldName, token, parser)) {
|
||||||
throw new QueryParsingException(parseContext, "[script] query does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext, "[script] query does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -114,6 +117,7 @@ public class ScriptQueryParser extends BaseQueryParserTemp {
|
||||||
if (queryName != null) {
|
if (queryName != null) {
|
||||||
parseContext.addNamedQuery(queryName, query);
|
parseContext.addNamedQuery(queryName, query);
|
||||||
}
|
}
|
||||||
|
query.setBoost(boost);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import java.util.TreeMap;
|
||||||
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html"
|
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html"
|
||||||
* > online documentation</a>.
|
* > online documentation</a>.
|
||||||
*/
|
*/
|
||||||
public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQueryStringBuilder> implements BoostableQueryBuilder<SimpleQueryStringBuilder> {
|
public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQueryStringBuilder> {
|
||||||
/** Default locale used for parsing.*/
|
/** Default locale used for parsing.*/
|
||||||
public static final Locale DEFAULT_LOCALE = Locale.ROOT;
|
public static final Locale DEFAULT_LOCALE = Locale.ROOT;
|
||||||
/** Default for lowercasing parsed terms.*/
|
/** Default for lowercasing parsed terms.*/
|
||||||
|
@ -54,18 +54,15 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
public static final boolean DEFAULT_LENIENT = false;
|
public static final boolean DEFAULT_LENIENT = false;
|
||||||
/** Default for wildcard analysis.*/
|
/** Default for wildcard analysis.*/
|
||||||
public static final boolean DEFAULT_ANALYZE_WILDCARD = false;
|
public static final boolean DEFAULT_ANALYZE_WILDCARD = false;
|
||||||
/** Default for boost to apply to resulting Lucene query. Defaults to 1.0*/
|
|
||||||
public static final float DEFAULT_BOOST = 1.0f;
|
|
||||||
/** Default for default operator to use for linking boolean clauses.*/
|
/** Default for default operator to use for linking boolean clauses.*/
|
||||||
public static final Operator DEFAULT_OPERATOR = Operator.OR;
|
public static final Operator DEFAULT_OPERATOR = Operator.OR;
|
||||||
/** Default for search flags to use. */
|
/** Default for search flags to use. */
|
||||||
public static final int DEFAULT_FLAGS = SimpleQueryStringFlag.ALL.value;
|
public static final int DEFAULT_FLAGS = SimpleQueryStringFlag.ALL.value;
|
||||||
/** Name for (de-)serialization. */
|
/** Name for (de-)serialization. */
|
||||||
public static final String NAME = "simple_query_string";
|
public static final String NAME = "simple_query_string";
|
||||||
|
|
||||||
/** Query text to parse. */
|
/** Query text to parse. */
|
||||||
private final String queryText;
|
private final String queryText;
|
||||||
/** Boost to apply to resulting Lucene query. Defaults to 1.0*/
|
|
||||||
private float boost = DEFAULT_BOOST;
|
|
||||||
/**
|
/**
|
||||||
* Fields to query against. If left empty will query default field,
|
* Fields to query against. If left empty will query default field,
|
||||||
* currently _ALL. Uses a TreeMap to hold the fields so boolean clauses are
|
* currently _ALL. Uses a TreeMap to hold the fields so boolean clauses are
|
||||||
|
@ -77,8 +74,6 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
private final Map<String, Float> fieldsAndWeights = new TreeMap<>();
|
private final Map<String, Float> fieldsAndWeights = new TreeMap<>();
|
||||||
/** If specified, analyzer to use to parse the query text, defaults to registered default in toQuery. */
|
/** If specified, analyzer to use to parse the query text, defaults to registered default in toQuery. */
|
||||||
private String analyzer;
|
private String analyzer;
|
||||||
/** Name of the query. Optional.*/
|
|
||||||
private String queryName;
|
|
||||||
/** Default operator to use for linking boolean clauses. Defaults to OR according to docs. */
|
/** Default operator to use for linking boolean clauses. Defaults to OR according to docs. */
|
||||||
private Operator defaultOperator = DEFAULT_OPERATOR;
|
private Operator defaultOperator = DEFAULT_OPERATOR;
|
||||||
/** If result is a boolean query, minimumShouldMatch parameter to apply. Ignored otherwise. */
|
/** If result is a boolean query, minimumShouldMatch parameter to apply. Ignored otherwise. */
|
||||||
|
@ -96,16 +91,6 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
this.queryText = queryText;
|
this.queryText = queryText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SimpleQueryStringBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the boost to apply to resulting Lucene query.*/
|
|
||||||
public float boost() {
|
|
||||||
return this.boost;
|
|
||||||
}
|
|
||||||
/** Returns the text to parse the query from. */
|
/** Returns the text to parse the query from. */
|
||||||
public String text() {
|
public String text() {
|
||||||
return this.queryText;
|
return this.queryText;
|
||||||
|
@ -116,7 +101,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
if (Strings.isEmpty(field)) {
|
if (Strings.isEmpty(field)) {
|
||||||
throw new IllegalArgumentException("supplied field is null or empty.");
|
throw new IllegalArgumentException("supplied field is null or empty.");
|
||||||
}
|
}
|
||||||
this.fieldsAndWeights.put(field, 1.0f);
|
this.fieldsAndWeights.put(field, AbstractQueryBuilder.DEFAULT_BOOST);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,17 +179,6 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
return this.flags;
|
return this.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the name for this query. */
|
|
||||||
public SimpleQueryStringBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the name for this query. */
|
|
||||||
public String queryName() {
|
|
||||||
return queryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether parsed terms for this query should be lower-cased.
|
* Specifies whether parsed terms for this query should be lower-cased.
|
||||||
* Defaults to true if not set.
|
* Defaults to true if not set.
|
||||||
|
@ -286,7 +260,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) {
|
protected Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
// Use the default field (_all) if no fields specified
|
// Use the default field (_all) if no fields specified
|
||||||
if (fieldsAndWeights.isEmpty()) {
|
if (fieldsAndWeights.isEmpty()) {
|
||||||
String field = parseContext.defaultField();
|
String field = parseContext.defaultField();
|
||||||
|
@ -309,23 +283,14 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
sqp.setDefaultOperator(defaultOperator.toBooleanClauseOccur());
|
sqp.setDefaultOperator(defaultOperator.toBooleanClauseOccur());
|
||||||
|
|
||||||
Query query = sqp.parse(queryText);
|
Query query = sqp.parse(queryText);
|
||||||
if (queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minimumShouldMatch != null && query instanceof BooleanQuery) {
|
if (minimumShouldMatch != null && query instanceof BooleanQuery) {
|
||||||
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
|
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// safety check - https://github.com/elastic/elasticsearch/pull/11696#discussion-diff-32532468
|
|
||||||
if (query != null) {
|
|
||||||
query.setBoost(boost);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
|
||||||
builder.field("query", queryText);
|
builder.field("query", queryText);
|
||||||
|
@ -355,15 +320,11 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
builder.field("analyze_wildcard", settings.analyzeWildcard());
|
builder.field("analyze_wildcard", settings.analyzeWildcard());
|
||||||
builder.field("locale", (settings.locale().toLanguageTag()));
|
builder.field("locale", (settings.locale().toLanguageTag()));
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minimumShouldMatch != null) {
|
if (minimumShouldMatch != null) {
|
||||||
builder.field("minimum_should_match", minimumShouldMatch);
|
builder.field("minimum_should_match", minimumShouldMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.field("boost", boost);
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,9 +334,8 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SimpleQueryStringBuilder readFrom(StreamInput in) throws IOException {
|
protected SimpleQueryStringBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SimpleQueryStringBuilder result = new SimpleQueryStringBuilder(in.readString());
|
SimpleQueryStringBuilder result = new SimpleQueryStringBuilder(in.readString());
|
||||||
result.boost = in.readFloat();
|
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
Map<String, Float> fields = new HashMap<>();
|
Map<String, Float> fields = new HashMap<>();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
@ -384,28 +344,21 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
fields.put(field, weight);
|
fields.put(field, weight);
|
||||||
}
|
}
|
||||||
result.fieldsAndWeights.putAll(fields);
|
result.fieldsAndWeights.putAll(fields);
|
||||||
|
|
||||||
result.flags = in.readInt();
|
result.flags = in.readInt();
|
||||||
result.analyzer = in.readOptionalString();
|
result.analyzer = in.readOptionalString();
|
||||||
|
|
||||||
result.defaultOperator = Operator.readOperatorFrom(in);
|
result.defaultOperator = Operator.readOperatorFrom(in);
|
||||||
result.settings.lowercaseExpandedTerms(in.readBoolean());
|
result.settings.lowercaseExpandedTerms(in.readBoolean());
|
||||||
result.settings.lenient(in.readBoolean());
|
result.settings.lenient(in.readBoolean());
|
||||||
result.settings.analyzeWildcard(in.readBoolean());
|
result.settings.analyzeWildcard(in.readBoolean());
|
||||||
|
|
||||||
String localeStr = in.readString();
|
String localeStr = in.readString();
|
||||||
result.settings.locale(Locale.forLanguageTag(localeStr));
|
result.settings.locale(Locale.forLanguageTag(localeStr));
|
||||||
|
|
||||||
result.queryName = in.readOptionalString();
|
|
||||||
result.minimumShouldMatch = in.readOptionalString();
|
result.minimumShouldMatch = in.readOptionalString();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(queryText);
|
out.writeString(queryText);
|
||||||
out.writeFloat(boost);
|
|
||||||
out.writeInt(fieldsAndWeights.size());
|
out.writeInt(fieldsAndWeights.size());
|
||||||
for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
|
for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
|
||||||
out.writeString(entry.getKey());
|
out.writeString(entry.getKey());
|
||||||
|
@ -418,21 +371,19 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
out.writeBoolean(settings.lenient());
|
out.writeBoolean(settings.lenient());
|
||||||
out.writeBoolean(settings.analyzeWildcard());
|
out.writeBoolean(settings.analyzeWildcard());
|
||||||
out.writeString(settings.locale().toLanguageTag());
|
out.writeString(settings.locale().toLanguageTag());
|
||||||
|
|
||||||
out.writeOptionalString(queryName);
|
|
||||||
out.writeOptionalString(minimumShouldMatch);
|
out.writeOptionalString(minimumShouldMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
protected int doHashCode() {
|
||||||
return Objects.hash(fieldsAndWeights, analyzer, defaultOperator, queryText, queryName, minimumShouldMatch, settings, flags);
|
return Objects.hash(fieldsAndWeights, analyzer, defaultOperator, queryText, minimumShouldMatch, settings, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doEquals(SimpleQueryStringBuilder other) {
|
protected boolean doEquals(SimpleQueryStringBuilder other) {
|
||||||
return Objects.equals(fieldsAndWeights, other.fieldsAndWeights) && Objects.equals(analyzer, other.analyzer)
|
return Objects.equals(fieldsAndWeights, other.fieldsAndWeights) && Objects.equals(analyzer, other.analyzer)
|
||||||
&& Objects.equals(defaultOperator, other.defaultOperator) && Objects.equals(queryText, other.queryText)
|
&& Objects.equals(defaultOperator, other.defaultOperator) && Objects.equals(queryText, other.queryText)
|
||||||
&& Objects.equals(queryName, other.queryName) && Objects.equals(minimumShouldMatch, other.minimumShouldMatch)
|
&& Objects.equals(minimumShouldMatch, other.minimumShouldMatch)
|
||||||
&& Objects.equals(settings, other.settings) && (flags == other.flags);
|
&& Objects.equals(settings, other.settings) && (flags == other.flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class SimpleQueryStringParser extends BaseQueryParser {
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
String queryBody = null;
|
String queryBody = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String field = null;
|
String field = null;
|
||||||
String minimumShouldMatch = null;
|
String minimumShouldMatch = null;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,13 +26,11 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Builder for {@link org.apache.lucene.search.spans.SpanContainingQuery}.
|
* Builder for {@link org.apache.lucene.search.spans.SpanContainingQuery}.
|
||||||
*/
|
*/
|
||||||
public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContainingQueryBuilder> implements SpanQueryBuilder<SpanContainingQueryBuilder>, BoostableQueryBuilder<SpanContainingQueryBuilder> {
|
public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContainingQueryBuilder> implements SpanQueryBuilder<SpanContainingQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "span_containing";
|
public static final String NAME = "span_containing";
|
||||||
private SpanQueryBuilder big;
|
private SpanQueryBuilder big;
|
||||||
private SpanQueryBuilder little;
|
private SpanQueryBuilder little;
|
||||||
private float boost = -1;
|
|
||||||
private String queryName;
|
|
||||||
static final SpanContainingQueryBuilder PROTOTYPE = new SpanContainingQueryBuilder();
|
static final SpanContainingQueryBuilder PROTOTYPE = new SpanContainingQueryBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,20 +49,6 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanContainingQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public SpanContainingQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (big == null) {
|
if (big == null) {
|
||||||
|
@ -82,14 +65,7 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
builder.field("little");
|
builder.field("little");
|
||||||
little.toXContent(builder, params);
|
little.toXContent(builder, params);
|
||||||
|
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +73,4 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SpanContainingQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
SpanQuery big = null;
|
SpanQuery big = null;
|
||||||
SpanQuery little = null;
|
SpanQuery little = null;
|
||||||
|
|
|
@ -19,12 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBuilder> implements SpanQueryBuilder<SpanFirstQueryBuilder>, BoostableQueryBuilder<SpanFirstQueryBuilder> {
|
public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBuilder> implements SpanQueryBuilder<SpanFirstQueryBuilder>{
|
||||||
|
|
||||||
public static final String NAME = "span_first";
|
public static final String NAME = "span_first";
|
||||||
|
|
||||||
|
@ -32,10 +31,6 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
||||||
|
|
||||||
private final int end;
|
private final int end;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final SpanFirstQueryBuilder SPAN_FIRST_QUERY_BUILDER = new SpanFirstQueryBuilder(null, -1);
|
static final SpanFirstQueryBuilder SPAN_FIRST_QUERY_BUILDER = new SpanFirstQueryBuilder(null, -1);
|
||||||
|
|
||||||
public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) {
|
public SpanFirstQueryBuilder(SpanQueryBuilder matchBuilder, int end) {
|
||||||
|
@ -43,32 +38,13 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
||||||
this.end = end;
|
this.end = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanFirstQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public SpanFirstQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field("match");
|
builder.field("match");
|
||||||
matchBuilder.toXContent(builder, params);
|
matchBuilder.toXContent(builder, params);
|
||||||
builder.field("end", end);
|
builder.field("end", end);
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +52,4 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SpanFirstQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
SpanQuery match = null;
|
SpanQuery match = null;
|
||||||
int end = -1;
|
int end = -1;
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -48,8 +47,14 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
public SpanMultiTermQueryBuilder boost(float boost) {
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
//no-op: SpanMultiTermQueryParser doesn't support boost, we should be consistent and ignore it here too.
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpanMultiTermQueryBuilder queryName(String queryName) {
|
||||||
|
//no-op: SpanMultiTermQueryParser doesn't support _name, we should be consistent and ignore it here too.
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,12 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuilder> implements SpanQueryBuilder<SpanNearQueryBuilder>, BoostableQueryBuilder<SpanNearQueryBuilder> {
|
public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuilder> implements SpanQueryBuilder<SpanNearQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "span_near";
|
public static final String NAME = "span_near";
|
||||||
|
|
||||||
|
@ -37,10 +36,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
|
|
||||||
private Boolean collectPayloads;
|
private Boolean collectPayloads;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder();
|
static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder();
|
||||||
|
|
||||||
public SpanNearQueryBuilder clause(SpanQueryBuilder clause) {
|
public SpanNearQueryBuilder clause(SpanQueryBuilder clause) {
|
||||||
|
@ -63,20 +58,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanNearQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public SpanNearQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (clauses.isEmpty()) {
|
if (clauses.isEmpty()) {
|
||||||
|
@ -98,12 +79,7 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
if (collectPayloads != null) {
|
if (collectPayloads != null) {
|
||||||
builder.field("collect_payloads", collectPayloads);
|
builder.field("collect_payloads", collectPayloads);
|
||||||
}
|
}
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,10 +87,4 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class SpanNearQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
Integer slop = null;
|
Integer slop = null;
|
||||||
boolean inOrder = true;
|
boolean inOrder = true;
|
||||||
boolean collectPayloads = true;
|
boolean collectPayloads = true;
|
||||||
|
|
|
@ -19,12 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilder> implements SpanQueryBuilder<SpanNotQueryBuilder>, BoostableQueryBuilder<SpanNotQueryBuilder> {
|
public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilder> implements SpanQueryBuilder<SpanNotQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "span_not";
|
public static final String NAME = "span_not";
|
||||||
|
|
||||||
|
@ -38,10 +37,6 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
|
|
||||||
private Integer post;
|
private Integer post;
|
||||||
|
|
||||||
private Float boost;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final SpanNotQueryBuilder PROTOTYPE = new SpanNotQueryBuilder();
|
static final SpanNotQueryBuilder PROTOTYPE = new SpanNotQueryBuilder();
|
||||||
|
|
||||||
public SpanNotQueryBuilder include(SpanQueryBuilder include) {
|
public SpanNotQueryBuilder include(SpanQueryBuilder include) {
|
||||||
|
@ -69,22 +64,6 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanNotQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
* @param queryName The query name
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public SpanNotQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (include == null) {
|
if (include == null) {
|
||||||
|
@ -112,12 +91,7 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
builder.field("post", post);
|
builder.field("post", post);
|
||||||
}
|
}
|
||||||
if (boost != null) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,10 +99,4 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SpanNotQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
|
||||||
SpanQuery include = null;
|
SpanQuery include = null;
|
||||||
SpanQuery exclude = null;
|
SpanQuery exclude = null;
|
||||||
|
|
|
@ -19,22 +19,17 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder> implements SpanQueryBuilder<SpanOrQueryBuilder>, BoostableQueryBuilder<SpanOrQueryBuilder> {
|
public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder> implements SpanQueryBuilder<SpanOrQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "span_or";
|
public static final String NAME = "span_or";
|
||||||
|
|
||||||
private ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();
|
private ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder();
|
static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder();
|
||||||
|
|
||||||
public SpanOrQueryBuilder clause(SpanQueryBuilder clause) {
|
public SpanOrQueryBuilder clause(SpanQueryBuilder clause) {
|
||||||
|
@ -42,20 +37,6 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanOrQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public SpanOrQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (clauses.isEmpty()) {
|
if (clauses.isEmpty()) {
|
||||||
|
@ -67,12 +48,7 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
clause.toXContent(builder, params);
|
clause.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,10 +56,4 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class SpanOrQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
List<SpanQuery> clauses = newArrayList();
|
List<SpanQuery> clauses = newArrayList();
|
||||||
|
|
|
@ -19,15 +19,9 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for a specific type of {@link QueryBuilder} that allows to build span queries
|
* Marker interface for a specific type of {@link QueryBuilder} that allows to build span queries
|
||||||
*/
|
*/
|
||||||
public interface SpanQueryBuilder<QB extends SpanQueryBuilder> extends QueryBuilder<QB> {
|
public interface SpanQueryBuilder<QB extends SpanQueryBuilder> extends QueryBuilder<QB> {
|
||||||
|
|
||||||
@Override
|
|
||||||
SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Span Query that matches documents containing a term.
|
* A Span Query that matches documents containing a term.
|
||||||
* @see SpanTermQuery
|
* @see SpanTermQuery
|
||||||
|
@ -66,7 +68,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpanQuery toQuery(QueryParseContext context) {
|
public SpanQuery doToQuery(QueryParseContext context) throws IOException {
|
||||||
BytesRef valueBytes = null;
|
BytesRef valueBytes = null;
|
||||||
String fieldName = this.fieldName;
|
String fieldName = this.fieldName;
|
||||||
MappedFieldType mapper = context.fieldMapper(fieldName);
|
MappedFieldType mapper = context.fieldMapper(fieldName);
|
||||||
|
@ -77,13 +79,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
||||||
if (valueBytes == null) {
|
if (valueBytes == null) {
|
||||||
valueBytes = BytesRefs.toBytesRef(this.value);
|
valueBytes = BytesRefs.toBytesRef(this.value);
|
||||||
}
|
}
|
||||||
|
return new SpanTermQuery(new Term(fieldName, valueBytes));
|
||||||
SpanTermQuery query = new SpanTermQuery(new Term(fieldName, valueBytes));
|
|
||||||
query.setBoost(boost);
|
|
||||||
if (queryName != null) {
|
|
||||||
context.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class SpanTermQueryParser extends BaseQueryParser {
|
||||||
|
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
if (token == XContentParser.Token.START_OBJECT) {
|
if (token == XContentParser.Token.START_OBJECT) {
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.spans.SpanQuery;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,13 +26,11 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Builder for {@link org.apache.lucene.search.spans.SpanWithinQuery}.
|
* Builder for {@link org.apache.lucene.search.spans.SpanWithinQuery}.
|
||||||
*/
|
*/
|
||||||
public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQueryBuilder> implements SpanQueryBuilder<SpanWithinQueryBuilder>, BoostableQueryBuilder<SpanWithinQueryBuilder> {
|
public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQueryBuilder> implements SpanQueryBuilder<SpanWithinQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "span_within";
|
public static final String NAME = "span_within";
|
||||||
private SpanQueryBuilder big;
|
private SpanQueryBuilder big;
|
||||||
private SpanQueryBuilder little;
|
private SpanQueryBuilder little;
|
||||||
private float boost = -1;
|
|
||||||
private String queryName;
|
|
||||||
static final SpanWithinQueryBuilder PROTOTYPE = new SpanWithinQueryBuilder();
|
static final SpanWithinQueryBuilder PROTOTYPE = new SpanWithinQueryBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,20 +49,6 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanWithinQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public SpanWithinQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (big == null) {
|
if (big == null) {
|
||||||
|
@ -82,13 +65,7 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
builder.field("little");
|
builder.field("little");
|
||||||
little.toXContent(builder, params);
|
little.toXContent(builder, params);
|
||||||
|
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
@ -97,10 +74,4 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SpanQuery toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {
|
|
||||||
//norelease just a temporary implementation, will go away once this query is refactored and properly overrides toQuery
|
|
||||||
return (SpanQuery)super.toQuery(parseContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SpanWithinQueryParser extends BaseQueryParserTemp {
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
SpanQuery big = null;
|
SpanQuery big = null;
|
||||||
SpanQuery little = null;
|
SpanQuery little = null;
|
||||||
|
|
|
@ -25,10 +25,12 @@ import org.apache.lucene.search.TermQuery;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Query that matches documents containing a term.
|
* A Query that matches documents containing a term.
|
||||||
*/
|
*/
|
||||||
public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> implements BoostableQueryBuilder<TermQueryBuilder> {
|
public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "term";
|
public static final String NAME = "term";
|
||||||
static final TermQueryBuilder PROTOTYPE = new TermQueryBuilder(null, null);
|
static final TermQueryBuilder PROTOTYPE = new TermQueryBuilder(null, null);
|
||||||
|
@ -69,7 +71,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query toQuery(QueryParseContext parseContext) {
|
public Query doToQuery(QueryParseContext parseContext) throws IOException {
|
||||||
Query query = null;
|
Query query = null;
|
||||||
MappedFieldType mapper = parseContext.fieldMapper(this.fieldName);
|
MappedFieldType mapper = parseContext.fieldMapper(this.fieldName);
|
||||||
if (mapper != null) {
|
if (mapper != null) {
|
||||||
|
@ -78,10 +80,6 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> imp
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
query = new TermQuery(new Term(this.fieldName, BytesRefs.toBytesRef(this.value)));
|
query = new TermQuery(new Term(this.fieldName, BytesRefs.toBytesRef(this.value)));
|
||||||
}
|
}
|
||||||
query.setBoost(this.boost);
|
|
||||||
if (this.queryName != null) {
|
|
||||||
parseContext.addNamedQuery(queryName, query);
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TermQueryParser extends BaseQueryParser {
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
Object value = null;
|
Object value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> implements BoostableQueryBuilder<TermsQueryBuilder> {
|
public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
||||||
|
|
||||||
public static final String NAME = "terms";
|
public static final String NAME = "terms";
|
||||||
|
|
||||||
|
@ -36,8 +36,6 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> i
|
||||||
|
|
||||||
private final Object values;
|
private final Object values;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
private String execution;
|
private String execution;
|
||||||
|
|
||||||
private String lookupIndex;
|
private String lookupIndex;
|
||||||
|
@ -47,8 +45,6 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> i
|
||||||
private String lookupPath;
|
private String lookupPath;
|
||||||
private Boolean lookupCache;
|
private Boolean lookupCache;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
|
@ -136,14 +132,6 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> i
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public TermsQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the index name to lookup the terms from.
|
* Sets the index name to lookup the terms from.
|
||||||
*/
|
*/
|
||||||
|
@ -186,12 +174,6 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> i
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TermsQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
|
@ -217,13 +199,7 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> i
|
||||||
builder.field("execution", execution);
|
builder.field("execution", execution);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boost != -1) {
|
printBoostAndQueryName(builder);
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
builder.field("value", type);
|
builder.field("value", type);
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,30 @@ public class TypeQueryParser extends BaseQueryParserTemp {
|
||||||
@Override
|
@Override
|
||||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
String queryName = null;
|
||||||
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
|
BytesRef type = null;
|
||||||
|
String currentFieldName = null;
|
||||||
|
XContentParser.Token token;
|
||||||
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
currentFieldName = parser.currentName();
|
||||||
|
} else if (token.isValue()) {
|
||||||
|
if ("_name".equals(currentFieldName)) {
|
||||||
|
queryName = parser.text();
|
||||||
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
|
boost = parser.floatValue();
|
||||||
|
} else if ("value".equals(currentFieldName)) {
|
||||||
|
type = parser.utf8Bytes();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new QueryParsingException(parseContext, "[type] filter doesn't support [" + currentFieldName + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XContentParser.Token token = parser.nextToken();
|
if (type == null) {
|
||||||
if (token != XContentParser.Token.FIELD_NAME) {
|
throw new QueryParsingException(parseContext, "[type] filter needs to be provided with a value for the type");
|
||||||
throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
|
|
||||||
}
|
}
|
||||||
String fieldName = parser.currentName();
|
|
||||||
if (!fieldName.equals("value")) {
|
|
||||||
throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
|
|
||||||
}
|
|
||||||
token = parser.nextToken();
|
|
||||||
if (token != XContentParser.Token.VALUE_STRING) {
|
|
||||||
throw new QueryParsingException(parseContext, "[type] filter should have a value field, and the type name");
|
|
||||||
}
|
|
||||||
BytesRef type = parser.utf8Bytes();
|
|
||||||
// move to the next token
|
|
||||||
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?
|
||||||
|
@ -69,6 +77,12 @@ public class TypeQueryParser extends BaseQueryParserTemp {
|
||||||
} else {
|
} else {
|
||||||
filter = documentMapper.typeFilter();
|
filter = documentMapper.typeFilter();
|
||||||
}
|
}
|
||||||
|
if (queryName != null) {
|
||||||
|
parseContext.addNamedQuery(queryName, filter);
|
||||||
|
}
|
||||||
|
if (filter != null) {
|
||||||
|
filter.setBoost(boost);
|
||||||
|
}
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
||||||
* a Wildcard term should not start with one of the wildcards <tt>*</tt> or
|
* a Wildcard term should not start with one of the wildcards <tt>*</tt> or
|
||||||
* <tt>?</tt>.
|
* <tt>?</tt>.
|
||||||
*/
|
*/
|
||||||
public class WildcardQueryBuilder extends MultiTermQueryBuilder implements BoostableQueryBuilder<WildcardQueryBuilder> {
|
public class WildcardQueryBuilder extends MultiTermQueryBuilder {
|
||||||
|
|
||||||
public static final String NAME = "wildcard";
|
public static final String NAME = "wildcard";
|
||||||
|
|
||||||
|
@ -39,12 +39,8 @@ public class WildcardQueryBuilder extends MultiTermQueryBuilder implements Boost
|
||||||
|
|
||||||
private final String wildcard;
|
private final String wildcard;
|
||||||
|
|
||||||
private float boost = -1;
|
|
||||||
|
|
||||||
private String rewrite;
|
private String rewrite;
|
||||||
|
|
||||||
private String queryName;
|
|
||||||
|
|
||||||
static final WildcardQueryBuilder PROTOTYPE = new WildcardQueryBuilder(null, null);
|
static final WildcardQueryBuilder PROTOTYPE = new WildcardQueryBuilder(null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,43 +64,16 @@ public class WildcardQueryBuilder extends MultiTermQueryBuilder implements Boost
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public WildcardQueryBuilder boost(float boost) {
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
|
|
||||||
*/
|
|
||||||
public WildcardQueryBuilder queryName(String queryName) {
|
|
||||||
this.queryName = queryName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(NAME);
|
builder.startObject(NAME);
|
||||||
if (boost == -1 && rewrite == null && queryName == null) {
|
builder.startObject(name);
|
||||||
builder.field(name, wildcard);
|
builder.field("wildcard", wildcard);
|
||||||
} else {
|
if (rewrite != null) {
|
||||||
builder.startObject(name);
|
builder.field("rewrite", rewrite);
|
||||||
builder.field("wildcard", wildcard);
|
|
||||||
if (boost != -1) {
|
|
||||||
builder.field("boost", boost);
|
|
||||||
}
|
|
||||||
if (rewrite != null) {
|
|
||||||
builder.field("rewrite", rewrite);
|
|
||||||
}
|
|
||||||
if (queryName != null) {
|
|
||||||
builder.field("_name", queryName);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
|
printBoostAndQueryName(builder);
|
||||||
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
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.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.query.support.QueryParsers;
|
import org.elasticsearch.index.query.support.QueryParsers;
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ public class WildcardQueryParser extends BaseQueryParserTemp {
|
||||||
String rewriteMethod = null;
|
String rewriteMethod = null;
|
||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
float boost = 1.0f;
|
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
if (token == XContentParser.Token.START_OBJECT) {
|
if (token == XContentParser.Token.START_OBJECT) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue