Search in sources :

Example 76 with MatchAllDocsQuery

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"));
}
Also used : Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) HashSet(java.util.HashSet)

Example 77 with MatchAllDocsQuery

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();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) PhraseQuery(org.apache.lucene.search.PhraseQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TopDocs(org.apache.lucene.search.TopDocs) Field(org.apache.lucene.document.Field) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) IndexReader(org.apache.lucene.index.IndexReader) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter)

Example 78 with MatchAllDocsQuery

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));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MultiReader(org.apache.lucene.index.MultiReader) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexReader(org.apache.lucene.index.IndexReader) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 79 with MatchAllDocsQuery

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 });
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) Term(org.apache.lucene.index.Term) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery)

Example 80 with MatchAllDocsQuery

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);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) Explanation(org.apache.lucene.search.Explanation) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery)

Aggregations

MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)288 IndexSearcher (org.apache.lucene.search.IndexSearcher)169 Directory (org.apache.lucene.store.Directory)133 Document (org.apache.lucene.document.Document)122 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)122 IndexReader (org.apache.lucene.index.IndexReader)120 TopDocs (org.apache.lucene.search.TopDocs)91 Sort (org.apache.lucene.search.Sort)71 SortField (org.apache.lucene.search.SortField)64 Query (org.apache.lucene.search.Query)53 BooleanQuery (org.apache.lucene.search.BooleanQuery)50 TermQuery (org.apache.lucene.search.TermQuery)49 FacetsCollector (org.apache.lucene.facet.FacetsCollector)40 Facets (org.apache.lucene.facet.Facets)34 Term (org.apache.lucene.index.Term)33 ArrayList (java.util.ArrayList)32 DirectoryReader (org.apache.lucene.index.DirectoryReader)30 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)28 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)23 FacetResult (org.apache.lucene.facet.FacetResult)22