From 5014d99c214536b8b71f97315861d3a449fbf2d8 Mon Sep 17 00:00:00 2001 From: David Wayne Smiley Date: Wed, 10 Jun 2015 12:54:36 +0000 Subject: [PATCH] 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 --- solr/CHANGES.txt | 3 +++ .../solr/highlight/DefaultSolrHighlighter.java | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 13604654d8c..b55553d0387 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 ---------------------- diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index 6136036f56f..463f1490c17 100644 --- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -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; }