From ca5f42a14edcd477f583d3caf5417b8994d133f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 3 Jan 2014 09:04:59 +0000 Subject: [PATCH] SOLR-5564: hl.maxAlternateFieldLength should apply to original field when fallback field does not exist git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1555035 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 5 ++++- .../apache/solr/highlight/DefaultSolrHighlighter.java | 4 ++++ .../org/apache/solr/highlight/HighlighterTest.java | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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 given amount, 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.java index 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 PluginInf String 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 listFields = new ArrayList(); 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.java index 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