mirror of https://github.com/apache/lucene.git
SOLR-825: Enables highlighting for range/wildcard/fuzzy/prefix queries if using hl.usePhraseHighlighter=true and hl.highlightMultiTerm=true.
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@775110 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
764b7989a8
commit
202a3311b7
|
@ -367,6 +367,9 @@ Bug Fixes
|
|||
|
||||
45. SOLR-1078: Fixes to WordDelimiterFilter to avoid splitting or dropping
|
||||
international non-letter characters such as non spacing marks. (yonik)
|
||||
|
||||
46. SOLR-825: Enables highlighting for range/wildcard/fuzzy/prefix queries if using hl.usePhraseHighlighter=true
|
||||
and hl.highlightMultiTerm=true. (Mark Miller)
|
||||
|
||||
|
||||
Other Changes
|
||||
|
|
|
@ -35,6 +35,7 @@ public interface HighlightParams {
|
|||
public static final String ALTERNATE_FIELD_LENGTH = HIGHLIGHT+".maxAlternateFieldLength";
|
||||
|
||||
public static final String USE_PHRASE_HIGHLIGHTER = HIGHLIGHT+".usePhraseHighlighter";
|
||||
public static final String HIGHLIGHT_MULTI_TERM = HIGHLIGHT+".highlightMultiTerm";
|
||||
|
||||
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
||||
// Formatter
|
||||
|
|
|
@ -79,11 +79,16 @@ public class HighlightComponent extends SearchComponent
|
|||
}
|
||||
}
|
||||
|
||||
if(highlightQuery != null) {
|
||||
boolean rewrite = !(Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER)) && Boolean.valueOf(req.getParams().get(HighlightParams.HIGHLIGHT_MULTI_TERM)));
|
||||
highlightQuery = rewrite ? highlightQuery.rewrite(req.getSearcher().getReader()) : highlightQuery;
|
||||
}
|
||||
|
||||
// No highlighting if there is no query -- consider q.alt="*:*
|
||||
if( highlightQuery != null ) {
|
||||
NamedList sumData = highlighter.doHighlighting(
|
||||
rb.getResults().docList,
|
||||
highlightQuery.rewrite(req.getSearcher().getReader()),
|
||||
highlightQuery,
|
||||
req, defaultHighlightFields );
|
||||
|
||||
if(sumData != null) {
|
||||
|
|
|
@ -131,11 +131,16 @@ public class DefaultSolrHighlighter extends SolrHighlighter
|
|||
*/
|
||||
private SpanScorer getSpanQueryScorer(Query query, String fieldName, CachingTokenFilter tokenStream, SolrQueryRequest request) throws IOException {
|
||||
boolean reqFieldMatch = request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false);
|
||||
Boolean highlightMultiTerm = request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM);
|
||||
if(highlightMultiTerm == null) {
|
||||
highlightMultiTerm = false;
|
||||
}
|
||||
|
||||
if (reqFieldMatch) {
|
||||
return new SpanScorer(query, fieldName, tokenStream);
|
||||
return new SpanScorer(query, fieldName, tokenStream, highlightMultiTerm);
|
||||
}
|
||||
else {
|
||||
return new SpanScorer(query, null, tokenStream);
|
||||
return new SpanScorer(query, null, tokenStream, highlightMultiTerm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,14 +142,18 @@ public class SolrQueryParser extends QueryParser {
|
|||
// TODO: throw exception if field type doesn't support prefixes?
|
||||
// (sortable numeric types don't do prefixes, but can do range queries)
|
||||
Term t = new Term(field, termStr);
|
||||
return new ConstantScorePrefixQuery(t);
|
||||
PrefixQuery prefixQuery = new PrefixQuery(t);
|
||||
prefixQuery.setConstantScoreRewrite(true);
|
||||
return prefixQuery;
|
||||
}
|
||||
|
||||
protected Query getWildcardQuery(String field, String termStr) throws ParseException {
|
||||
Query q = super.getWildcardQuery(field, termStr);
|
||||
if (q instanceof WildcardQuery) {
|
||||
// use a constant score query to avoid overflowing clauses
|
||||
return new ConstantScoreQuery(new WildcardFilter(((WildcardQuery)q).getTerm()));
|
||||
WildcardQuery wildcardQuery = new WildcardQuery(((WildcardQuery)q).getTerm());
|
||||
wildcardQuery.setConstantScoreRewrite(true);
|
||||
return wildcardQuery;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
|
|
@ -672,4 +672,50 @@ public class HighlighterTest extends AbstractSolrTestCase {
|
|||
assertEquals("Expected to highlight on field \"foo_s\"", "foo_s",
|
||||
highlightFieldNames.get(0));
|
||||
}
|
||||
|
||||
public void testDefaultFieldPrefixWildcardHighlight() {
|
||||
|
||||
// do summarization using re-analysis of the field
|
||||
HashMap<String,String> args = new HashMap<String,String>();
|
||||
args.put("hl", "true");
|
||||
args.put("df", "t_text");
|
||||
args.put("hl.fl", "");
|
||||
args.put("hl.usePhraseHighlighter", "true");
|
||||
args.put("hl.highlightMultiTerm", "true");
|
||||
TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
|
||||
"standard", 0, 200, args);
|
||||
|
||||
assertU(adoc("t_text", "a long day's night", "id", "1"));
|
||||
assertU(commit());
|
||||
assertU(optimize());
|
||||
assertQ("Basic summarization",
|
||||
sumLRF.makeRequest("lon*"),
|
||||
"//lst[@name='highlighting']/lst[@name='1']",
|
||||
"//lst[@name='1']/arr[@name='t_text']/str"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void testDefaultFieldNonPrefixWildcardHighlight() {
|
||||
|
||||
// do summarization using re-analysis of the field
|
||||
HashMap<String,String> args = new HashMap<String,String>();
|
||||
args.put("hl", "true");
|
||||
args.put("df", "t_text");
|
||||
args.put("hl.fl", "");
|
||||
args.put("hl.usePhraseHighlighter", "true");
|
||||
args.put("hl.highlightMultiTerm", "true");
|
||||
TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
|
||||
"standard", 0, 200, args);
|
||||
|
||||
assertU(adoc("t_text", "a long day's night", "id", "1"));
|
||||
assertU(commit());
|
||||
assertU(optimize());
|
||||
assertQ("Basic summarization",
|
||||
sumLRF.makeRequest("l*g"),
|
||||
"//lst[@name='highlighting']/lst[@name='1']",
|
||||
"//lst[@name='1']/arr[@name='t_text']/str"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue