Skip to content

Commit

Permalink
Set per query builder "boost" and "query name" support (#28390)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbismuth committed Oct 5, 2018
1 parent 6effd0a commit 6349cb3
Show file tree
Hide file tree
Showing 50 changed files with 560 additions and 29 deletions.
Expand Up @@ -43,6 +43,16 @@

public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
Expand Down
Expand Up @@ -82,6 +82,16 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue

boolean requiresRewrite = false;

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
Expand Down
Expand Up @@ -67,6 +67,16 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ

boolean requiresRewrite = false;

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
Expand Down
Expand Up @@ -56,6 +56,16 @@ public class ParentIdQueryBuilderTests extends AbstractQueryTestCase<ParentIdQue
private static final String PARENT_NAME = "parent";
private static final String CHILD_NAME = "child";

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(ParentJoinPlugin.class);
Expand Down Expand Up @@ -153,5 +163,4 @@ public void testIgnoreUnmapped() throws IOException {
QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext()));
assertThat(e.getMessage(), containsString("[" + ParentIdQueryBuilder.NAME + "] no relation found for child [unmapped]"));
}

}
Expand Up @@ -77,6 +77,16 @@ public class PercolateQueryBuilderTests extends AbstractQueryTestCase<PercolateQ

private boolean indexedDocumentExists = true;

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singleton(PercolatorPlugin.class);
Expand Down Expand Up @@ -301,5 +311,4 @@ public void testFieldAlias() throws IOException {
assertEquals(query.getCandidateMatchesQuery(), aliasQuery.getCandidateMatchesQuery());
assertEquals(query.getVerifiedMatchesQuery(), aliasQuery.getVerifiedMatchesQuery());
}

}
Expand Up @@ -114,7 +114,11 @@ public static SpanOrQueryBuilder fromXContent(XContentParser parser) throws IOEx
if (query instanceof SpanQueryBuilder == false) {
throw new ParsingException(parser.getTokenLocation(), "spanOr [clauses] must be of type span query");
}
clauses.add((SpanQueryBuilder) query);
final SpanQueryBuilder clause = (SpanQueryBuilder) query;
if (clause.boost() != AbstractQueryBuilder.DEFAULT_BOOST) {
throw new ParsingException(parser.getTokenLocation(), "spanOr [clauses] can't have boost value");
}
clauses.add(clause);
}
} else {
throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
Expand Down
Expand Up @@ -53,6 +53,16 @@ public class RangeFieldQueryStringQueryBuilderTests extends AbstractQueryTestCas
private static final String DATE_RANGE_FIELD_NAME = "mapped_date_range";
private static final String IP_RANGE_FIELD_NAME = "mapped_ip_range";

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
Expand Down
Expand Up @@ -48,6 +48,17 @@
import static org.hamcrest.CoreMatchers.instanceOf;

public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected BoolQueryBuilder doCreateTestQueryBuilder() {
BoolQueryBuilder query = new BoolQueryBuilder();
Expand Down
Expand Up @@ -31,6 +31,16 @@

public class BoostingQueryBuilderTests extends AbstractQueryTestCase<BoostingQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected BoostingQueryBuilder doCreateTestQueryBuilder() {
BoostingQueryBuilder query = new BoostingQueryBuilder(RandomQueryBuilder.createQuery(random()), RandomQueryBuilder.createQuery(random()));
Expand Down
Expand Up @@ -39,6 +39,16 @@

public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase<CommonTermsQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected CommonTermsQueryBuilder doCreateTestQueryBuilder() {
int numberOfTerms = randomIntBetween(0, 10);
Expand Down
Expand Up @@ -33,6 +33,17 @@
import static org.hamcrest.Matchers.containsString;

public class ConstantScoreQueryBuilderTests extends AbstractQueryTestCase<ConstantScoreQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

/**
* @return a {@link ConstantScoreQueryBuilder} with random boost between 0.1f and 2.0f
*/
Expand Down
Expand Up @@ -39,6 +39,17 @@
import static org.hamcrest.Matchers.instanceOf;

public class DisMaxQueryBuilderTests extends AbstractQueryTestCase<DisMaxQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

/**
* @return a {@link DisMaxQueryBuilder} with random inner queries
*/
Expand Down
Expand Up @@ -43,6 +43,17 @@
import static org.hamcrest.CoreMatchers.instanceOf;

public class ExistsQueryBuilderTests extends AbstractQueryTestCase<ExistsQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected ExistsQueryBuilder doCreateTestQueryBuilder() {
String fieldPattern;
Expand Down
Expand Up @@ -30,6 +30,17 @@
import static org.hamcrest.CoreMatchers.instanceOf;

public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<FieldMaskingSpanQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected FieldMaskingSpanQueryBuilder doCreateTestQueryBuilder() {
String fieldName;
Expand Down
Expand Up @@ -39,6 +39,16 @@

public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected FuzzyQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
Expand Down
Expand Up @@ -44,6 +44,16 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
/** Randomly generate either NaN or one of the two infinity values. */
private static Double[] brokenDoubles = {Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME);
Expand Down
Expand Up @@ -41,6 +41,16 @@

public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDistanceQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected GeoDistanceQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME);
Expand Down
Expand Up @@ -42,6 +42,17 @@
import static org.hamcrest.CoreMatchers.notNullValue;

public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygonQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected GeoPolygonQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME);
Expand Down
Expand Up @@ -61,6 +61,16 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
private static String indexedShapeRouting;
private static ShapeBuilder<?, ?> indexedShapeToReturn;

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected GeoShapeQueryBuilder doCreateTestQueryBuilder() {
return doCreateTestQueryBuilder(randomBoolean());
Expand Down
Expand Up @@ -38,6 +38,16 @@

public class IdsQueryBuilderTests extends AbstractQueryTestCase<IdsQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected IdsQueryBuilder doCreateTestQueryBuilder() {
final String type;
Expand Down
Expand Up @@ -30,6 +30,16 @@

public class MatchAllQueryBuilderTests extends AbstractQueryTestCase<MatchAllQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected MatchAllQueryBuilder doCreateTestQueryBuilder() {
return new MatchAllQueryBuilder();
Expand Down
Expand Up @@ -30,6 +30,16 @@

public class MatchNoneQueryBuilderTests extends AbstractQueryTestCase<MatchNoneQueryBuilder> {

@Override
protected boolean supportsBoost() {
return true;
}

@Override
protected boolean supportsQueryName() {
return true;
}

@Override
protected MatchNoneQueryBuilder doCreateTestQueryBuilder() {
return new MatchNoneQueryBuilder();
Expand Down

0 comments on commit 6349cb3

Please sign in to comment.