Apache Lucene open-source search software
SOLR-5564: hl.maxAlternateFieldLength should apply to original field when fallback field does not exist
Jan Høydahlca5f42a14edc
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 25d071fda92..d6705daebb4 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -197,7 +197,7 @@ Bug Fixes* SOLR-5577: Likely ZooKeeper expiration should not slow down updates a givenamount, but instead cut off updates after a given time.(Mark Miller, Christine Poerschke)-+Optimizations----------------------@@ -335,6 +335,9 @@ Bug Fixes* SOLR-5588: PeerSync doesn't count all connect failures as success.(Mark Miller)+* SOLR-5564: hl.maxAlternateFieldLength should apply to original field when+ fallback is attempted (janhoy)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.javaindex c10b587c97a..db2f01fe003 100644--- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java+++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java@@ -602,6 +602,10 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInfString alternateField = params.getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD);if (alternateField != null && alternateField.length() > 0) {StorableField[] docFields = doc.getFields(alternateField);+ if (docFields.length == 0) {+ // The alternate field did not exist, treat the original field as fallback instead+ docFields = doc.getFields(fieldName);+ }List<String> listFields = new ArrayList<String>();for (StorableField field : docFields) {if (field.binaryValue() == null)diff --git a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.javaindex de4edbfe565..22078edd5b5 100644--- a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java+++ b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java@@ -660,6 +660,16 @@ public class HighlighterTest extends SolrTestCaseJ4 {"//lst[@name='highlighting']/lst[@name='1' and count(*)=1]","//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='a piece of text']");++ // with a non-existing alternate field + max length+ args.put("hl.alternateField", "NonExistingField");+ args.put("hl.maxAlternateFieldLength", "15");+ sumLRF = h.getRequestFactory("standard", 0, 200, args);+ assertQ("Alternate summarization",+ sumLRF.makeRequest("tv_text:keyword"),+ "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",+ "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='a piece of text']"+ );}@Test