Search in sources :

Example 6 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_blendedTermQuery.

public void testExtractQueryMetadata_blendedTermQuery() {
    Term[] termsArr = new Term[] { new Term("_field", "_term1"), new Term("_field", "_term2") };
    BlendedTermQuery commonTermsQuery = BlendedTermQuery.booleanBlendedQuery(termsArr, false);
    Result result = analyze(commonTermsQuery);
    assertThat(result.verified, is(true));
    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) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 7 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_booleanQuery.

public void testExtractQueryMetadata_booleanQuery() {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    builder.add(termQuery1, BooleanClause.Occur.SHOULD);
    PhraseQuery phraseQuery = new PhraseQuery("_field", "_term1", "term2");
    builder.add(phraseQuery, BooleanClause.Occur.SHOULD);
    BooleanQuery.Builder subBuilder = new BooleanQuery.Builder();
    TermQuery termQuery2 = new TermQuery(new Term("_field1", "_term"));
    subBuilder.add(termQuery2, BooleanClause.Occur.MUST);
    TermQuery termQuery3 = new TermQuery(new Term("_field3", "_long_term"));
    subBuilder.add(termQuery3, BooleanClause.Occur.MUST);
    builder.add(subBuilder.build(), BooleanClause.Occur.SHOULD);
    BooleanQuery booleanQuery = builder.build();
    Result result = analyze(booleanQuery);
    assertThat("Should clause with phrase query isn't verified, so entire query can't be verified", result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    Collections.sort(terms);
    assertThat(terms.size(), equalTo(3));
    assertThat(terms.get(0).field(), equalTo(termQuery1.getTerm().field()));
    assertThat(terms.get(0).bytes(), equalTo(termQuery1.getTerm().bytes()));
    assertThat(terms.get(1).field(), equalTo(phraseQuery.getTerms()[0].field()));
    assertThat(terms.get(1).bytes(), equalTo(phraseQuery.getTerms()[0].bytes()));
    assertThat(terms.get(2).field(), equalTo(termQuery3.getTerm().field()));
    assertThat(terms.get(2).bytes(), equalTo(termQuery3.getTerm().bytes()));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) TermQuery(org.apache.lucene.search.TermQuery) 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)

Example 8 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_spanFirstQuery.

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

Example 9 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_termsQuery.

public void testExtractQueryMetadata_termsQuery() {
    TermInSetQuery termsQuery = new TermInSetQuery("_field", new BytesRef("_term1"), new BytesRef("_term2"));
    Result result = analyze(termsQuery);
    assertThat(result.verified, is(true));
    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 : TermInSetQuery(org.apache.lucene.search.TermInSetQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) BytesRef(org.apache.lucene.util.BytesRef) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 10 with Result

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

the class QueryAnalyzerTests method testExtractQueryMetadata_multiPhraseQuery.

public void testExtractQueryMetadata_multiPhraseQuery() {
    MultiPhraseQuery multiPhraseQuery = new MultiPhraseQuery.Builder().add(new Term("_field", "_long_term")).add(new Term[] { new Term("_field", "_long_term"), new Term("_field", "_term") }).add(new Term[] { new Term("_field", "_long_term"), new Term("_field", "_very_long_term") }).add(new Term[] { new Term("_field", "_very_long_term") }).build();
    Result result = analyze(multiPhraseQuery);
    assertThat(result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    assertThat(terms.size(), equalTo(1));
    assertThat(terms.get(0).field(), equalTo("_field"));
    assertThat(terms.get(0).bytes().utf8ToString(), equalTo("_very_long_term"));
}
Also used : ArrayList(java.util.ArrayList) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) 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