Adding utility method to SpanTermQueryBuilderTest that outputs certain amount of queries with same fieldname
This commit is contained in:
parent
afe4fb4a27
commit
8e20536f0f
|
@ -37,11 +37,8 @@ public class SpanContainingQueryBuilderTest extends BaseQueryTestCase<SpanContai
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanContainingQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanContainingQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanTermQueryBuilder bigQuery = new SpanTermQueryBuilderTest().createTestQueryBuilder();
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(2);
|
||||||
// we need same field name and value type as bigQuery for little query
|
return new SpanContainingQueryBuilder(spanTermQueries[0], spanTermQueries[1]);
|
||||||
String fieldName = bigQuery.fieldName();
|
|
||||||
SpanTermQueryBuilder littleQuery = new SpanTermQueryBuilder(fieldName, randomValueForField(fieldName));
|
|
||||||
return new SpanContainingQueryBuilder(bigQuery, littleQuery);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class SpanFirstQueryBuilderTest extends BaseQueryTestCase<SpanFirstQueryB
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanFirstQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanFirstQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanTermQueryBuilder innerQueryBuilder = new SpanTermQueryBuilderTest().createTestQueryBuilder();
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(1);
|
||||||
return new SpanFirstQueryBuilder(innerQueryBuilder, randomIntBetween(0, 1000));
|
return new SpanFirstQueryBuilder(spanTermQueries[0], randomIntBetween(0, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -45,12 +45,9 @@ public class SpanNearQueryBuilderTest extends BaseQueryTestCase<SpanNearQueryBui
|
||||||
@Override
|
@Override
|
||||||
protected SpanNearQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanNearQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(randomIntBetween(-10, 10));
|
SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(randomIntBetween(-10, 10));
|
||||||
int clauses = randomIntBetween(1, 6);
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(randomIntBetween(1, 6));
|
||||||
// we use one random SpanTermQueryBuilder to determine same field name for subsequent clauses
|
for (SpanTermQueryBuilder clause : spanTermQueries) {
|
||||||
String fieldName = new SpanTermQueryBuilderTest().createTestQueryBuilder().fieldName();
|
queryBuilder.clause(clause);
|
||||||
for (int i = 0; i < clauses; i++) {
|
|
||||||
// we need same field name in all clauses, so we only randomize value
|
|
||||||
queryBuilder.clause(new SpanTermQueryBuilder(fieldName, randomValueForField(fieldName)));
|
|
||||||
}
|
}
|
||||||
queryBuilder.inOrder(randomBoolean());
|
queryBuilder.inOrder(randomBoolean());
|
||||||
queryBuilder.collectPayloads(randomBoolean());
|
queryBuilder.collectPayloads(randomBoolean());
|
||||||
|
|
|
@ -45,19 +45,8 @@ public class SpanNotQueryBuilderTest extends BaseQueryTestCase<SpanNotQueryBuild
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanNotQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanNotQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanTermQueryBuilder includeQuery = new SpanTermQueryBuilderTest().createTestQueryBuilder();
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(2);
|
||||||
// we need same field name and value type as bigQuery for little query
|
SpanNotQueryBuilder queryBuilder = new SpanNotQueryBuilder(spanTermQueries[0], spanTermQueries[1]);
|
||||||
String fieldName = includeQuery.fieldName();
|
|
||||||
Object value;
|
|
||||||
switch (fieldName) {
|
|
||||||
case BOOLEAN_FIELD_NAME: value = randomBoolean(); break;
|
|
||||||
case INT_FIELD_NAME: value = randomInt(); break;
|
|
||||||
case DOUBLE_FIELD_NAME: value = randomDouble(); break;
|
|
||||||
case STRING_FIELD_NAME: value = randomAsciiOfLengthBetween(1, 10); break;
|
|
||||||
default : value = randomAsciiOfLengthBetween(1, 10);
|
|
||||||
}
|
|
||||||
SpanTermQueryBuilder excludeQuery = new SpanTermQueryBuilder(fieldName, value);
|
|
||||||
SpanNotQueryBuilder queryBuilder = new SpanNotQueryBuilder(includeQuery, excludeQuery);
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
// also test negative values, they should implicitly be changed to 0
|
// also test negative values, they should implicitly be changed to 0
|
||||||
queryBuilder.dist(randomIntBetween(-2, 10));
|
queryBuilder.dist(randomIntBetween(-2, 10));
|
||||||
|
|
|
@ -44,12 +44,9 @@ public class SpanOrQueryBuilderTest extends BaseQueryTestCase<SpanOrQueryBuilder
|
||||||
@Override
|
@Override
|
||||||
protected SpanOrQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanOrQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder();
|
SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder();
|
||||||
int clauses = randomIntBetween(1, 6);
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(randomIntBetween(1, 6));
|
||||||
// we use one random SpanTermQueryBuilder to determine same field name for subsequent clauses
|
for (SpanTermQueryBuilder clause : spanTermQueries) {
|
||||||
String fieldName = new SpanTermQueryBuilderTest().createTestQueryBuilder().fieldName();
|
queryBuilder.clause(clause);
|
||||||
for (int i = 0; i < clauses; i++) {
|
|
||||||
// we need same field name in all clauses, so we only randomize value
|
|
||||||
queryBuilder.clause(new SpanTermQueryBuilder(fieldName, randomValueForField(fieldName)));
|
|
||||||
}
|
}
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,26 @@ public class SpanTermQueryBuilderTest extends BaseTermQueryTestCase<SpanTermQuer
|
||||||
protected Query createLuceneTermQuery(Term term) {
|
protected Query createLuceneTermQuery(Term term) {
|
||||||
return new SpanTermQuery(term);
|
return new SpanTermQuery(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param amount the number of clauses that will be returned
|
||||||
|
* @return an array of random {@link SpanTermQueryBuilder} with same field name
|
||||||
|
*/
|
||||||
|
public SpanTermQueryBuilder[] createSpanTermQueryBuilders(int amount) {
|
||||||
|
SpanTermQueryBuilder[] clauses = new SpanTermQueryBuilder[amount];
|
||||||
|
SpanTermQueryBuilder first = createTestQueryBuilder();
|
||||||
|
clauses[0] = first;
|
||||||
|
for (int i = 1; i < amount; i++) {
|
||||||
|
// we need same field name in all clauses, so we only randomize value
|
||||||
|
SpanTermQueryBuilder spanTermQuery = new SpanTermQueryBuilder(first.fieldName(), randomValueForField(first.fieldName()));
|
||||||
|
if (randomBoolean()) {
|
||||||
|
spanTermQuery.boost(2.0f / randomIntBetween(1, 20));
|
||||||
|
}
|
||||||
|
if (randomBoolean()) {
|
||||||
|
spanTermQuery.queryName(randomAsciiOfLengthBetween(1, 10));
|
||||||
|
}
|
||||||
|
clauses[i] = spanTermQuery;
|
||||||
|
}
|
||||||
|
return clauses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,19 +37,8 @@ public class SpanWithinQueryBuilderTest extends BaseQueryTestCase<SpanWithinQuer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanWithinQueryBuilder doCreateTestQueryBuilder() {
|
protected SpanWithinQueryBuilder doCreateTestQueryBuilder() {
|
||||||
SpanTermQueryBuilder bigQuery = new SpanTermQueryBuilderTest().createTestQueryBuilder();
|
SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTest().createSpanTermQueryBuilders(2);
|
||||||
// we need same field name and value type as bigQuery for little query
|
return new SpanWithinQueryBuilder(spanTermQueries[0], spanTermQueries[1]);
|
||||||
String fieldName = bigQuery.fieldName();
|
|
||||||
Object littleValue;
|
|
||||||
switch (fieldName) {
|
|
||||||
case BOOLEAN_FIELD_NAME: littleValue = randomBoolean(); break;
|
|
||||||
case INT_FIELD_NAME: littleValue = randomInt(); break;
|
|
||||||
case DOUBLE_FIELD_NAME: littleValue = randomDouble(); break;
|
|
||||||
case STRING_FIELD_NAME: littleValue = randomAsciiOfLengthBetween(1, 10); break;
|
|
||||||
default : littleValue = randomAsciiOfLengthBetween(1, 10);
|
|
||||||
}
|
|
||||||
SpanTermQueryBuilder littleQuery = new SpanTermQueryBuilder(fieldName, littleValue);
|
|
||||||
return new SpanWithinQueryBuilder(bigQuery, littleQuery);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue