use of org.apache.lucene.search.PhraseQuery in project lucene-solr by apache.
the class TestQPHelper method testCJKSloppyPhrase.
public void testCJKSloppyPhrase() throws Exception {
// individual CJK chars as terms
SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer();
PhraseQuery expected = new PhraseQuery(3, "field", "中", "国");
assertEquals(expected, getQuery("\"中国\"~3", analyzer));
}
use of org.apache.lucene.search.PhraseQuery in project lucene-solr by apache.
the class TestSimpleQueryParser method testORPhrase.
/** test some OR'd phrases using '|' operator */
public void testORPhrase() throws Exception {
PhraseQuery phrase1 = new PhraseQuery("field", "foo", "bar");
PhraseQuery phrase2 = new PhraseQuery("field", "star", "wars");
BooleanQuery.Builder expected = new BooleanQuery.Builder();
expected.add(phrase1, Occur.SHOULD);
expected.add(phrase2, Occur.SHOULD);
assertEquals(expected.build(), parse("\"foo bar\"|\"star wars\""));
}
use of org.apache.lucene.search.PhraseQuery in project lucene-solr by apache.
the class TestSimpleQueryParser method testANDPhrase.
/** test some AND'd phrases using '+' operator */
public void testANDPhrase() throws Exception {
PhraseQuery phrase1 = new PhraseQuery("field", "foo", "bar");
PhraseQuery phrase2 = new PhraseQuery("field", "star", "wars");
BooleanQuery.Builder expected = new BooleanQuery.Builder();
expected.add(phrase1, Occur.MUST);
expected.add(phrase2, Occur.MUST);
assertEquals(expected.build(), parse("\"foo bar\"+\"star wars\""));
}
use of org.apache.lucene.search.PhraseQuery in project lucene-solr by apache.
the class TestSimpleQueryParser method testDisableSlop.
public void testDisableSlop() {
PhraseQuery expectedPhrase = new PhraseQuery("field", "foo", "bar");
BooleanQuery.Builder expected = new BooleanQuery.Builder();
expected.add(expectedPhrase, Occur.MUST);
expected.add(new TermQuery(new Term("field", "~2")), Occur.MUST);
assertEquals(expected.build(), parse("\"foo bar\"~2", ~NEAR_OPERATOR));
}
use of org.apache.lucene.search.PhraseQuery in project lucene-solr by apache.
the class ShingleAnalyzerWrapperTest method testShingleAnalyzerWrapperPhraseQuery.
/*
* This shows how to construct a phrase query containing shingles.
*/
public void testShingleAnalyzerWrapperPhraseQuery() throws Exception {
PhraseQuery.Builder builder = new PhraseQuery.Builder();
try (TokenStream ts = analyzer.tokenStream("content", "this sentence")) {
int j = -1;
PositionIncrementAttribute posIncrAtt = ts.addAttribute(PositionIncrementAttribute.class);
CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
ts.reset();
while (ts.incrementToken()) {
j += posIncrAtt.getPositionIncrement();
String termText = termAtt.toString();
builder.add(new Term("content", termText), j);
}
ts.end();
}
PhraseQuery q = builder.build();
ScoreDoc[] hits = searcher.search(q, 1000).scoreDocs;
int[] ranks = new int[] { 0 };
compareRanks(hits, ranks);
}
Aggregations