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));
}
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", "中国"));
}
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", "中国国"));
}
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));
}
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));
}
Aggregations