use of org.apache.lucene.search.spans.SpanTermQuery in project lucene-solr by apache.
the class TestPayloadExplanations method testOrderedNearQuery.
public void testOrderedNearQuery() throws Exception {
SpanNearQuery q = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(FIELD, "w3")), new SpanTermQuery(new Term(FIELD, "w2")) }, 1, true);
testAllFunctions(q, new int[] { 1, 3 });
}
use of org.apache.lucene.search.spans.SpanTermQuery in project lucene-solr by apache.
the class TestPayloadExplanations method testUnorderedNearQuery.
public void testUnorderedNearQuery() throws Exception {
SpanNearQuery q = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(FIELD, "w2")), new SpanTermQuery(new Term(FIELD, "w3")) }, 1, false);
testAllFunctions(q, new int[] { 0, 1, 2, 3 });
}
use of org.apache.lucene.search.spans.SpanTermQuery in project lucene-solr by apache.
the class TestUnifiedHighlighterStrictPhrases method testRewriteAndMtq.
/**
* Test it does *not* highlight the same term's not next to the span-near. "charlie" in this case.
* This particular example exercises "Rewrite" plus "MTQ" in the same query.
*/
public void testRewriteAndMtq() throws IOException {
indexWriter.addDocument(newDoc("alpha bravo charlie - charlie bravo alpha"));
initReaderSearcherHighlighter();
SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term("body", "bravo")), // REWRITES
new SpanMultiTermQueryWrapper<>(new PrefixQuery(new Term("body", "ch"))) }, 0, true);
BooleanQuery query = new BooleanQuery.Builder().add(snq, BooleanClause.Occur.MUST).add(new PrefixQuery(new Term("body", "al")), // MTQ
BooleanClause.Occur.MUST).add(newPhraseQuery("body", "alpha bravo"), BooleanClause.Occur.MUST).add(newPhraseQuery("title", "bravo alpha"), BooleanClause.Occur.SHOULD).build();
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
String[] snippets = highlighter.highlight("body", query, topDocs);
assertArrayEquals(new String[] { "<b>alpha</b> <b>bravo</b> <b>charlie</b> - charlie bravo <b>alpha</b>" }, snippets);
// do again, this time with MTQ disabled. We should only find "alpha bravo".
//disable but leave phrase processing enabled
highlighter.setHandleMultiTermQuery(false);
topDocs = searcher.search(query, 10, Sort.INDEXORDER);
snippets = highlighter.highlight("body", query, topDocs);
assertArrayEquals(new String[] { "<b>alpha</b> <b>bravo</b> charlie - charlie bravo alpha" }, snippets);
}
use of org.apache.lucene.search.spans.SpanTermQuery in project lucene-solr by apache.
the class TestUnifiedHighlighterStrictPhrases method testFilteredOutSpan.
public void testFilteredOutSpan() throws IOException {
indexWriter.addDocument(newDoc("freezing cold stuff like stuff freedom of speech"));
initReaderSearcherHighlighter();
WildcardQuery wildcardQuery = new WildcardQuery(new Term("body", "free*"));
SpanMultiTermQueryWrapper<WildcardQuery> wildcardSpanQuery = new SpanMultiTermQueryWrapper<>(wildcardQuery);
SpanTermQuery termQuery = new SpanTermQuery(new Term("body", "speech"));
SpanQuery spanQuery = new SpanNearQuery(new SpanQuery[] { wildcardSpanQuery, termQuery }, 3, false);
BooleanQuery query = new BooleanQuery.Builder().add(spanQuery, BooleanClause.Occur.MUST).build();
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
String[] snippets = highlighter.highlight("body", query, topDocs);
assertArrayEquals(new String[] { "freezing cold stuff like stuff <b>freedom</b> of <b>speech</b>" }, snippets);
}
use of org.apache.lucene.search.spans.SpanTermQuery in project lucene-solr by apache.
the class TestUnifiedHighlighterStrictPhrases method testRewrite.
/**
* Like {@link #testRewriteAndMtq} but no freestanding MTQ
*/
public void testRewrite() throws IOException {
indexWriter.addDocument(newDoc("alpha bravo charlie - charlie bravo alpha"));
initReaderSearcherHighlighter();
SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term("body", "bravo")), // REWRITES
new SpanMultiTermQueryWrapper<>(new PrefixQuery(new Term("body", "ch"))) }, 0, true);
BooleanQuery query = new BooleanQuery.Builder().add(snq, BooleanClause.Occur.MUST).add(newPhraseQuery("body", "alpha bravo"), BooleanClause.Occur.MUST).add(newPhraseQuery("title", "bravo alpha"), BooleanClause.Occur.SHOULD).build();
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
String[] snippets = highlighter.highlight("body", query, topDocs);
assertArrayEquals(new String[] { "<b>alpha</b> <b>bravo</b> <b>charlie</b> - charlie bravo alpha" }, snippets);
// do again, this time with MTQ disabled. We should only find "alpha bravo".
//disable but leave phrase processing enabled
highlighter.setHandleMultiTermQuery(false);
topDocs = searcher.search(query, 10, Sort.INDEXORDER);
snippets = highlighter.highlight("body", query, topDocs);
assertArrayEquals(new String[] { "<b>alpha</b> <b>bravo</b> charlie - charlie bravo alpha" }, snippets);
}
Aggregations