SOLR-7655: Speed up DefaultSolrHighlighter's check for the existence of payloads

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1684665 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2015-06-10 12:54:36 +00:00
parent b80afc5e00
commit 5014d99c21
2 changed files with 17 additions and 2 deletions

View File

@ -180,6 +180,9 @@ Bug Fixes
(Mark Miller, Adam McElwee)
* SOLR-7638: Fix new (Angular-based) admin UI Cloud pane (Upayavira via ehatcher)
* SOLR-7655: The DefaultSolrHighlighter since 5.0 was determining if payloads were present in a way
that was slow, especially when lots of fields were highlighted. It's now fast. (David Smiley)
Other Changes
----------------------

View File

@ -39,6 +39,7 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.StorableField;
import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.index.Terms;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.highlight.Encoder;
import org.apache.lucene.search.highlight.Formatter;
@ -213,8 +214,19 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
QueryScorer scorer = new QueryScorer(query,
request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false) ? fieldName : null);
scorer.setExpandMultiTermQuery(request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM, true));
scorer.setUsePayloads(request.getParams().getFieldBool(fieldName, HighlightParams.PAYLOADS,
request.getSearcher().getLeafReader().getFieldInfos().fieldInfo(fieldName).hasPayloads()));
boolean defaultPayloads = true;//overwritten below
try {
// It'd be nice to know if payloads are on the tokenStream but the presence of the attribute isn't a good
// indicator.
final Terms terms = request.getSearcher().getLeafReader().fields().terms(fieldName);
if (terms != null) {
defaultPayloads = terms.hasPayloads();
}
} catch (IOException e) {
log.error("Couldn't check for existence of payloads", e);
}
scorer.setUsePayloads(request.getParams().getFieldBool(fieldName, HighlightParams.PAYLOADS, defaultPayloads));
return scorer;
}