Search in sources :

Example 1 with SpanGapQueryBuilder

use of org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder in project OpenSearch by opensearch-project.

the class SpanGapQueryBuilderTests method doAssertLuceneQuery.

@Override
protected void doAssertLuceneQuery(SpanNearQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
    assertThat(query, either(instanceOf(SpanNearQuery.class)).or(instanceOf(SpanTermQuery.class)).or(instanceOf(SpanBoostQuery.class)).or(instanceOf(MatchAllQueryBuilder.class)));
    if (query instanceof SpanNearQuery) {
        SpanNearQuery spanNearQuery = (SpanNearQuery) query;
        assertThat(spanNearQuery.getSlop(), equalTo(queryBuilder.slop()));
        assertThat(spanNearQuery.isInOrder(), equalTo(queryBuilder.inOrder()));
        assertThat(spanNearQuery.getClauses().length, equalTo(queryBuilder.clauses().size()));
        Iterator<SpanQueryBuilder> spanQueryBuilderIterator = queryBuilder.clauses().iterator();
        for (SpanQuery spanQuery : spanNearQuery.getClauses()) {
            SpanQueryBuilder spanQB = spanQueryBuilderIterator.next();
            if (spanQB instanceof SpanGapQueryBuilder)
                continue;
            assertThat(spanQuery, equalTo(spanQB.toQuery(context)));
        }
    } else if (query instanceof SpanTermQuery || query instanceof SpanBoostQuery) {
        assertThat(queryBuilder.clauses().size(), equalTo(1));
        assertThat(query, equalTo(queryBuilder.clauses().get(0).toQuery(context)));
    }
}
Also used : SpanGapQueryBuilder(org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 2 with SpanGapQueryBuilder

use of org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder in project OpenSearch by opensearch-project.

the class SpanGapQueryBuilderTests method testIllegalArguments.

public void testIllegalArguments() {
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SpanGapQueryBuilder(null, 1));
    assertEquals("[span_gap] field name is null or empty", e.getMessage());
}
Also used : SpanGapQueryBuilder(org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder)

Example 3 with SpanGapQueryBuilder

use of org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder in project OpenSearch by opensearch-project.

the class SpanGapQueryBuilderTests method doCreateTestQueryBuilder.

@Override
protected SpanNearQueryBuilder doCreateTestQueryBuilder() {
    SpanTermQueryBuilder[] spanTermQueries = new SpanTermQueryBuilderTests().createSpanTermQueryBuilders(randomIntBetween(1, 6));
    SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(spanTermQueries[0], randomIntBetween(-10, 10));
    for (int i = 1; i < spanTermQueries.length; i++) {
        SpanTermQueryBuilder termQB = spanTermQueries[i];
        queryBuilder.addClause(termQB);
        if (i % 2 == 1) {
            SpanGapQueryBuilder gapQB = new SpanGapQueryBuilder(termQB.fieldName(), randomIntBetween(1, 2));
            queryBuilder.addClause(gapQB);
        }
    }
    queryBuilder.inOrder(true);
    return queryBuilder;
}
Also used : SpanGapQueryBuilder(org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder)

Aggregations

SpanGapQueryBuilder (org.opensearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder)3 SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)1 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1