Search in sources :

Example 21 with SynonymQuery

use of org.apache.lucene.search.SynonymQuery in project lucene-solr by apache.

the class TestQueryBuilder method testCJKSynonymsAND.

/** synonyms with default AND operator */
public void testCJKSynonymsAND() throws Exception {
    BooleanQuery.Builder expected = new BooleanQuery.Builder();
    expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
    SynonymQuery inner = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner, BooleanClause.Occur.MUST);
    QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
    assertEquals(expected.build(), builder.createBooleanQuery("field", "中国", BooleanClause.Occur.MUST));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) Term(org.apache.lucene.index.Term)

Example 22 with SynonymQuery

use of org.apache.lucene.search.SynonymQuery in project lucene-solr by apache.

the class TestQueryBuilder method testCJKSynonymsOR.

/** synonyms with default OR operator */
public void testCJKSynonymsOR() throws Exception {
    BooleanQuery.Builder expected = new BooleanQuery.Builder();
    expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
    SynonymQuery inner = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner, BooleanClause.Occur.SHOULD);
    QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
    assertEquals(expected.build(), builder.createBooleanQuery("field", "中国"));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) Term(org.apache.lucene.index.Term)

Example 23 with SynonymQuery

use of org.apache.lucene.search.SynonymQuery in project lucene-solr by apache.

the class TestQueryBuilder method testCJKSynonymsOR2.

/** more complex synonyms with default OR operator */
public void testCJKSynonymsOR2() throws Exception {
    BooleanQuery.Builder expected = new BooleanQuery.Builder();
    expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
    SynonymQuery inner = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner, BooleanClause.Occur.SHOULD);
    SynonymQuery inner2 = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner2, BooleanClause.Occur.SHOULD);
    QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
    assertEquals(expected.build(), builder.createBooleanQuery("field", "中国国"));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) Term(org.apache.lucene.index.Term)

Example 24 with SynonymQuery

use of org.apache.lucene.search.SynonymQuery in project lucene-solr by apache.

the class TestQueryBuilder method testCJKSynonym.

/** simple CJK synonym test */
public void testCJKSynonym() throws Exception {
    SynonymQuery expected = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
    assertEquals(expected, builder.createBooleanQuery("field", "国"));
    assertEquals(expected, builder.createPhraseQuery("field", "国"));
    assertEquals(expected, builder.createBooleanQuery("field", "国", BooleanClause.Occur.MUST));
}
Also used : SynonymQuery(org.apache.lucene.search.SynonymQuery) Term(org.apache.lucene.index.Term)

Example 25 with SynonymQuery

use of org.apache.lucene.search.SynonymQuery in project lucene-solr by apache.

the class TestQueryBuilder method testCJKSynonymsAND2.

/** more complex synonyms with default AND operator */
public void testCJKSynonymsAND2() throws Exception {
    BooleanQuery.Builder expected = new BooleanQuery.Builder();
    expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
    SynonymQuery inner = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner, BooleanClause.Occur.MUST);
    SynonymQuery inner2 = new SynonymQuery(new Term("field", "国"), new Term("field", "國"));
    expected.add(inner2, BooleanClause.Occur.MUST);
    QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
    assertEquals(expected.build(), builder.createBooleanQuery("field", "中国国", BooleanClause.Occur.MUST));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) Term(org.apache.lucene.index.Term)

Aggregations

Term (org.apache.lucene.index.Term)25 SynonymQuery (org.apache.lucene.search.SynonymQuery)25 BooleanQuery (org.apache.lucene.search.BooleanQuery)21 TermQuery (org.apache.lucene.search.TermQuery)20 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)17 Query (org.apache.lucene.search.Query)16 BoostQuery (org.apache.lucene.search.BoostQuery)15 PhraseQuery (org.apache.lucene.search.PhraseQuery)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)13 MultiPhraseQuery (org.apache.lucene.search.MultiPhraseQuery)12 SpanQuery (org.apache.lucene.search.spans.SpanQuery)12 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)11 BooleanClause (org.apache.lucene.search.BooleanClause)7 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)5 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)5 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)4 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)4 PrefixQuery (org.apache.lucene.search.PrefixQuery)4 ArrayList (java.util.ArrayList)3