Search in sources :

Example 1 with UnsupportedQueryException

use of org.elasticsearch.percolator.QueryAnalyzer.UnsupportedQueryException in project elasticsearch by elastic.

the class QueryAnalyzerTests method testExtractQueryMetadata_unsupportedQueryInBoolQueryWithMustClauses.

public void testExtractQueryMetadata_unsupportedQueryInBoolQueryWithMustClauses() {
    TermRangeQuery unsupportedQuery = new TermRangeQuery("_field", null, null, true, false);
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    BooleanQuery bq1 = builder.build();
    Result result = analyze(bq1);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, termQuery1.getTerm());
    TermQuery termQuery2 = new TermQuery(new Term("_field", "_longer_term"));
    builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.MUST);
    builder.add(termQuery2, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    bq1 = builder.build();
    result = analyze(bq1);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, termQuery2.getTerm());
    builder = new BooleanQuery.Builder();
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    BooleanQuery bq2 = builder.build();
    UnsupportedQueryException e = expectThrows(UnsupportedQueryException.class, () -> analyze(bq2));
    assertThat(e.getUnsupportedQuery(), sameInstance(unsupportedQuery));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) UnsupportedQueryException(org.elasticsearch.percolator.QueryAnalyzer.UnsupportedQueryException) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 2 with UnsupportedQueryException

use of org.elasticsearch.percolator.QueryAnalyzer.UnsupportedQueryException in project elasticsearch by elastic.

the class QueryAnalyzerTests method testExtractQueryMetadata_unsupportedQuery.

public void testExtractQueryMetadata_unsupportedQuery() {
    TermRangeQuery termRangeQuery = new TermRangeQuery("_field", null, null, true, false);
    UnsupportedQueryException e = expectThrows(UnsupportedQueryException.class, () -> analyze(termRangeQuery));
    assertThat(e.getUnsupportedQuery(), sameInstance(termRangeQuery));
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.SHOULD);
    builder.add(termRangeQuery, BooleanClause.Occur.SHOULD);
    BooleanQuery bq = builder.build();
    e = expectThrows(UnsupportedQueryException.class, () -> analyze(bq));
    assertThat(e.getUnsupportedQuery(), sameInstance(termRangeQuery));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) UnsupportedQueryException(org.elasticsearch.percolator.QueryAnalyzer.UnsupportedQueryException) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm)

Aggregations

Term (org.apache.lucene.index.Term)2 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)2 UnsupportedQueryException (org.elasticsearch.percolator.QueryAnalyzer.UnsupportedQueryException)2 QueryAnalyzer.selectTermListWithTheLongestShortestTerm (org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm)2 Result (org.elasticsearch.percolator.QueryAnalyzer.Result)1