Search in sources :

Example 1 with Result

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

the class QueryAnalyzerTests method testFunctionScoreQuery.

public void testFunctionScoreQuery() {
    TermQuery termQuery = new TermQuery(new Term("_field", "_value"));
    FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(termQuery, new RandomScoreFunction());
    Result result = analyze(functionScoreQuery);
    assertThat(result.verified, is(true));
    assertTermsEqual(result.terms, new Term("_field", "_value"));
    functionScoreQuery = new FunctionScoreQuery(termQuery, new RandomScoreFunction(), 1f, null, 10f);
    result = analyze(functionScoreQuery);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, new Term("_field", "_value"));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) TermQuery(org.apache.lucene.search.TermQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) RandomScoreFunction(org.elasticsearch.common.lucene.search.function.RandomScoreFunction) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 2 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_commonTermsQuery.

public void testExtractQueryMetadata_commonTermsQuery() {
    CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 100);
    commonTermsQuery.add(new Term("_field", "_term1"));
    commonTermsQuery.add(new Term("_field", "_term2"));
    Result result = analyze(commonTermsQuery);
    assertThat(result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    Collections.sort(terms);
    assertThat(terms.size(), equalTo(2));
    assertThat(terms.get(0).field(), equalTo("_field"));
    assertThat(terms.get(0).text(), equalTo("_term1"));
    assertThat(terms.get(1).field(), equalTo("_field"));
    assertThat(terms.get(1).text(), equalTo("_term2"));
}
Also used : ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) CommonTermsQuery(org.apache.lucene.queries.CommonTermsQuery) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 3 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_spanOrQuery.

public void testExtractQueryMetadata_spanOrQuery() {
    SpanTermQuery spanTermQuery1 = new SpanTermQuery(new Term("_field", "_short_term"));
    SpanTermQuery spanTermQuery2 = new SpanTermQuery(new Term("_field", "_very_long_term"));
    SpanOrQuery spanOrQuery = new SpanOrQuery(spanTermQuery1, spanTermQuery2);
    Result result = analyze(spanOrQuery);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, spanTermQuery1.getTerm(), spanTermQuery2.getTerm());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 4 with Result

use of org.elasticsearch.percolator.QueryAnalyzer.Result 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 5 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_phraseQuery.

public void testExtractQueryMetadata_phraseQuery() {
    PhraseQuery phraseQuery = new PhraseQuery("_field", "_term1", "term2");
    Result result = analyze(phraseQuery);
    assertThat(result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    assertThat(terms.size(), equalTo(1));
    assertThat(terms.get(0).field(), equalTo(phraseQuery.getTerms()[0].field()));
    assertThat(terms.get(0).bytes(), equalTo(phraseQuery.getTerms()[0].bytes()));
}
Also used : PhraseQuery(org.apache.lucene.search.PhraseQuery) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Aggregations

Term (org.apache.lucene.index.Term)23 Result (org.elasticsearch.percolator.QueryAnalyzer.Result)23 QueryAnalyzer.selectTermListWithTheLongestShortestTerm (org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm)23 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)17 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)13 ArrayList (java.util.ArrayList)12 TermQuery (org.apache.lucene.search.TermQuery)12 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 MultiPhraseQuery (org.apache.lucene.search.MultiPhraseQuery)6 PhraseQuery (org.apache.lucene.search.PhraseQuery)5 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 CommonTermsQuery (org.apache.lucene.queries.CommonTermsQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 SynonymQuery (org.apache.lucene.search.SynonymQuery)1 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1 SpanFirstQuery (org.apache.lucene.search.spans.SpanFirstQuery)1