mirror of https://github.com/apache/lucene.git
LUCENE-1752: Missing highlights when terms were repeated in separate, nested, boolean or disjunction queries.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@798976 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1286589fd5
commit
afb517e832
|
@ -42,6 +42,9 @@ Bug fixes
|
|||
8. LUCENE-1491: EdgeNGramTokenFilter no longer stops on tokens shorter than minimum n-gram size.
|
||||
(Todd Teak via Otis Gospodnetic)
|
||||
|
||||
9. LUCENE-1752: Missing highlights when terms were repeated in separate, nested, boolean or
|
||||
disjunction queries. (Koji Sekiguchi, Mark Miller)
|
||||
|
||||
New features
|
||||
|
||||
1. LUCENE-1531: Added support for BoostingTermQuery to XML query parser. (Karl Wettin)
|
||||
|
|
|
@ -98,13 +98,12 @@ public class WeightedSpanTermExtractor {
|
|||
private void extract(Query query, Map terms) throws IOException {
|
||||
if (query instanceof BooleanQuery) {
|
||||
BooleanClause[] queryClauses = ((BooleanQuery) query).getClauses();
|
||||
Map booleanTerms = new PositionCheckingMap();
|
||||
|
||||
for (int i = 0; i < queryClauses.length; i++) {
|
||||
if (!queryClauses[i].isProhibited()) {
|
||||
extract(queryClauses[i].getQuery(), booleanTerms);
|
||||
extract(queryClauses[i].getQuery(), terms);
|
||||
}
|
||||
}
|
||||
terms.putAll(booleanTerms);
|
||||
} else if (query instanceof PhraseQuery) {
|
||||
Term[] phraseQueryTerms = ((PhraseQuery) query).getTerms();
|
||||
SpanQuery[] clauses = new SpanQuery[phraseQueryTerms.length];
|
||||
|
@ -129,11 +128,9 @@ public class WeightedSpanTermExtractor {
|
|||
} else if (query instanceof FilteredQuery) {
|
||||
extract(((FilteredQuery) query).getQuery(), terms);
|
||||
} else if (query instanceof DisjunctionMaxQuery) {
|
||||
Map disjunctTerms = new PositionCheckingMap();
|
||||
for (Iterator iterator = ((DisjunctionMaxQuery) query).iterator(); iterator.hasNext();) {
|
||||
extract((Query) iterator.next(), disjunctTerms);
|
||||
extract((Query) iterator.next(), terms);
|
||||
}
|
||||
terms.putAll(disjunctTerms);
|
||||
} else if (query instanceof MultiTermQuery && (highlightCnstScrRngQuery || expandMultiTermQuery)) {
|
||||
MultiTermQuery mtq = ((MultiTermQuery)query);
|
||||
if(mtq.getRewriteMethod() != MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE) {
|
||||
|
|
|
@ -53,13 +53,13 @@ import org.apache.lucene.index.IndexWriter.MaxFieldLength;
|
|||
import org.apache.lucene.queryParser.ParseException;
|
||||
import org.apache.lucene.queryParser.QueryParser;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.MultiTermQuery;
|
||||
import org.apache.lucene.search.ConstantScoreRangeQuery;
|
||||
import org.apache.lucene.search.FilteredQuery;
|
||||
import org.apache.lucene.search.Hits;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MultiPhraseQuery;
|
||||
import org.apache.lucene.search.MultiSearcher;
|
||||
import org.apache.lucene.search.MultiTermQuery;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermRangeFilter;
|
||||
|
@ -178,6 +178,31 @@ public class HighlighterTest extends TestCase implements Formatter {
|
|||
// throw any exceptions
|
||||
}
|
||||
|
||||
// LUCENE-1752
|
||||
public void testRepeatingTermsInMultBooleans() throws Exception {
|
||||
String content = "x y z a b c d e f g b c g";
|
||||
String ph1 = "\"a b c d\"";
|
||||
String ph2 = "\"b c g\"";
|
||||
String f1 = "f1";
|
||||
String f2 = "f2";
|
||||
String f1c = f1 + ":";
|
||||
String f2c = f2 + ":";
|
||||
String q = "(" + f1c + ph1 + " OR " + f2c + ph1 + ") AND (" + f1c + ph2
|
||||
+ " OR " + f2c + ph2 + ")";
|
||||
Analyzer analyzer = new WhitespaceAnalyzer();
|
||||
QueryParser qp = new QueryParser(f1, analyzer);
|
||||
Query query = qp.parse(q);
|
||||
CachingTokenFilter stream = new CachingTokenFilter(analyzer.tokenStream(f1,
|
||||
new StringReader(content)));
|
||||
Scorer scorer = new SpanScorer(query, f1, stream, false);
|
||||
Highlighter h = new Highlighter(this, scorer);
|
||||
|
||||
h.getBestFragment(analyzer, f1, content);
|
||||
|
||||
assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
|
||||
numHighlights == 7);
|
||||
}
|
||||
|
||||
public void testSimpleSpanPhraseHighlighting() throws Exception {
|
||||
doSearching("\"very long and contains\"");
|
||||
|
||||
|
|
Loading…
Reference in New Issue