Search in sources :

Example 16 with SpanBoostQuery

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

the class TestUnifiedHighlighterMTQ method testSpanWildcard.

public void testSpanWildcard() 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);
    // wrap in a SpanBoostQuery to also show we see inside it
    Query query = new SpanBoostQuery(new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*"))), 2.0f);
    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]);
    ir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) WildcardQuery(org.apache.lucene.search.WildcardQuery) 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) TopDocs(org.apache.lucene.search.TopDocs) Field(org.apache.lucene.document.Field) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) IndexReader(org.apache.lucene.index.IndexReader) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter)

Example 17 with SpanBoostQuery

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

the class TestSolrCoreParser method unwrapSpanBoostQuery.

private static SpanQuery unwrapSpanBoostQuery(Query query) {
    assertTrue(query instanceof SpanBoostQuery);
    final SpanBoostQuery spanBoostQuery = (SpanBoostQuery) query;
    return spanBoostQuery.getQuery();
}
Also used : SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery)

Example 18 with SpanBoostQuery

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

the class TestPayloadExplanations method testPT2.

public void testPT2() throws Exception {
    for (PayloadFunction fn : functions) {
        SpanQuery q = pt("w1", fn);
        qtest(new SpanBoostQuery(q, 1000), new int[] { 0, 1, 2, 3 });
    }
}
Also used : SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Aggregations

SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)18 SpanQuery (org.apache.lucene.search.spans.SpanQuery)14 BoostQuery (org.apache.lucene.search.BoostQuery)6 Query (org.apache.lucene.search.Query)6 Term (org.apache.lucene.index.Term)5 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)5 ArrayList (java.util.ArrayList)4 TermQuery (org.apache.lucene.search.TermQuery)4 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)4 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)3 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)3 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)3 SpanNotQuery (org.apache.lucene.search.spans.SpanNotQuery)3 Element (org.w3c.dom.Element)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)2 PrefixQuery (org.apache.lucene.search.PrefixQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2