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();
}
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();
}
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 });
}
}
Aggregations