use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class FieldQueryTest method testFlattenToParentBlockJoinQuery.
public void testFlattenToParentBlockJoinQuery() throws Exception {
initBoost();
Query childQuery = tq(boost, "a");
Query query = new ToParentBlockJoinQuery(childQuery, new QueryBitSetProducer(new MatchAllDocsQuery()), ScoreMode.None);
FieldQuery fq = new FieldQuery(query, true, true);
Set<Query> flatQueries = new HashSet<>();
fq.flatten(query, reader, flatQueries, 1f);
assertCollectionQueries(flatQueries, tq(boost, "a"));
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class TestUnifiedHighlighterMTQ method testOneFuzzy.
public void testOneFuzzy() throws Exception {
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, indexAnalyzer);
Field body = new Field("body", "", fieldType);
Document doc = new Document();
doc.add(body);
body.setStringValue("This is a test.");
iw.addDocument(doc);
body.setStringValue("Test a one sentence document.");
iw.addDocument(doc);
IndexReader ir = iw.getReader();
iw.close();
IndexSearcher searcher = newSearcher(ir);
UnifiedHighlighter highlighter = new UnifiedHighlighter(searcher, indexAnalyzer);
Query query = new FuzzyQuery(new Term("body", "tets"), 1);
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
assertEquals(2, topDocs.totalHits);
String[] snippets = highlighter.highlight("body", query, topDocs);
assertEquals(2, snippets.length);
assertEquals("This is a <b>test</b>.", snippets[0]);
assertEquals("<b>Test</b> a one sentence document.", snippets[1]);
// with prefix
query = new FuzzyQuery(new Term("body", "tets"), 1, 2);
topDocs = searcher.search(query, 10, Sort.INDEXORDER);
assertEquals(2, topDocs.totalHits);
snippets = highlighter.highlight("body", query, topDocs);
assertEquals(2, snippets.length);
assertEquals("This is a <b>test</b>.", snippets[0]);
assertEquals("<b>Test</b> a one sentence document.", snippets[1]);
// wrong field
BooleanQuery bq = new BooleanQuery.Builder().add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD).add(new FuzzyQuery(new Term("bogus", "tets"), 1), BooleanClause.Occur.SHOULD).build();
topDocs = searcher.search(bq, 10, Sort.INDEXORDER);
assertEquals(2, topDocs.totalHits);
snippets = highlighter.highlight("body", bq, topDocs);
assertEquals(2, snippets.length);
assertEquals("This is a test.", snippets[0]);
assertEquals("Test a one sentence document.", snippets[1]);
ir.close();
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class BoostingQueryTest method testRewrite.
public void testRewrite() throws IOException {
IndexReader reader = new MultiReader();
BoostingQuery q = new BoostingQuery(new BooleanQuery.Builder().build(), new MatchAllDocsQuery(), 3);
Query rewritten = new IndexSearcher(reader).rewrite(q);
Query expectedRewritten = new BoostingQuery(new MatchNoDocsQuery(), new MatchAllDocsQuery(), 3);
assertEquals(expectedRewritten, rewritten);
assertSame(rewritten, rewritten.rewrite(reader));
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class TestFunctionScoreExplanations method testTopLevelBoost.
public void testTopLevelBoost() throws Exception {
Query q = new TermQuery(new Term(FIELD, "w1"));
FunctionScoreQuery csq = new FunctionScoreQuery(q, DoubleValuesSource.constant(5));
BooleanQuery.Builder bqB = new BooleanQuery.Builder();
bqB.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bqB.add(csq, BooleanClause.Occur.MUST);
BooleanQuery bq = bqB.build();
qtest(new BoostQuery(bq, 6), new int[] { 0, 1, 2, 3 });
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class TestFunctionScoreExplanations method testSubExplanations.
public void testSubExplanations() throws IOException {
Query query = new FunctionScoreQuery(new MatchAllDocsQuery(), DoubleValuesSource.constant(5));
IndexSearcher searcher = newSearcher(BaseExplanationTestCase.searcher.getIndexReader());
searcher.setSimilarity(new BM25Similarity());
Explanation expl = searcher.explain(query, 0);
assertEquals("constant(5.0)", expl.getDescription());
assertEquals(0, expl.getDetails().length);
query = new BoostQuery(query, 2);
expl = searcher.explain(query, 0);
assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[1].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[0].getDescription());
assertEquals(2f, expl.getDetails()[0].getValue(), 0f);
// in order to have a queryNorm != 1
searcher.setSimilarity(new ClassicSimilarity());
expl = searcher.explain(query, 0);
assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[1].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[0].getDescription());
assertEquals(2f, expl.getDetails()[0].getValue(), 0f);
}
Aggregations