This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new d1d4118 SOLR-10321: highlighting (unified): Don't return fields with
no highlights. (#487)
d1d4118 is described below
commit d1d4118a3b30654a7e09a5f900a6d6ff6e50d485
Author: David Smiley <[email protected]>
AuthorDate: Fri Jan 7 22:34:22 2022 -0500
SOLR-10321: highlighting (unified): Don't return fields with no highlights.
(#487)
In truth, the UH doesn't know the difference between a doc having a field
(but got no highlights) vs not having the field. This change is an
optimization in edge cases of highlighting many fields.
---
solr/CHANGES.txt | 3 +++
.../apache/solr/highlight/UnifiedSolrHighlighter.java | 2 --
.../solr/highlight/TestUnifiedSolrHighlighter.java | 19 +++++++++++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 11a0253..a784f0f 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 can
also 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.java
index 6f2c1a9..46f8255 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];
@Override
public void init(PluginInfo info) {
@@ -174,7 +173,6 @@ public class UnifiedSolrHighlighter extends SolrHighlighter
implements PluginInf
String 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.java
index a065fe2..3a2a70e 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>']}}}");
+ }
+
}