Apache Solr open-source search software
SOLR-10321: highlighting (unified): Don't return fields with no highlights. (#487)
David Smileyd1d4118a3b30
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 11a0253fed8..a784f0fda71 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -217,6 +217,9 @@ when told to. The admin UI now tells it to. (Nazerke Seidan, David Smiley)* SOLR-15213: Atomic updates: "add" now uses add-or-replace logic for child documents. They canalso themselves be atomic updates. (James Ashbourne, Endika Posadas via David Smiley)+* SOLR-10321: highlighting (hl.method=unified): When there are no highlights for a field, don't+ return the field in the response at all. (David Smiley)+* SOLR-15890: Add a limit to the Admin SQL panel if one is not included in the stmt (Joel Bernstein)* SOLR-15887: Remove <jmx/> from shipped solrconfig.xm. (Eric Pugh)diff --git a/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.javaindex 6f2c1a961b1..46f82558d5d 100644--- a/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java+++ b/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java@@ -118,7 +118,6 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;public class UnifiedSolrHighlighter extends SolrHighlighter implements PluginInfoInitialized {protected static final String SNIPPET_SEPARATOR = "\u0000";- private static final String[] ZERO_LEN_STR_ARRAY = new String[0];@Overridepublic void init(PluginInfo info) {@@ -174,7 +173,6 @@ public class UnifiedSolrHighlighter extends SolrHighlighter implements PluginInfString snippet = snippets.get(field)[i];if (snippet == null) {//TODO reuse logic of DefaultSolrHighlighter.alternateField- summary.add(field, ZERO_LEN_STR_ARRAY);} else {// we used a special snippet separator char and we can now split on it.summary.add(field, snippet.split(SNIPPET_SEPARATOR));diff --git a/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java b/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.javaindex a065fe249f1..3a2a70e5d10 100644--- a/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java+++ b/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java@@ -331,4 +331,23 @@ public class TestUnifiedSolrHighlighter extends SolrTestCaseJ4 {"count(//lst[@name='highlighting']/lst[@name='102']/arr[@name='text']/*)=1");}+ // SOLR-10321+ public void testDontReturnEmptyHighlights() throws Exception {+ clearIndex();+ // this doc has no value for field text2+ assertU(adoc("text", "third document", "id", "103"));+ assertU(commit());+ // query on text & text2. Assert we only highlight text; text2 shouldn't be present at all+ assertJQ(+ req(+ "q", "text:document OR text2:document",+ "hl", "true",+ "hl.fl", "text, text2",+ "sort", "id asc",+ "hl", "true"),+ "highlighting=={\n"+ + " '103':{\n"+ + " 'text':['third <em>document</em>']}}}");+ }+}