Apache Solr open-source search software
SOLR-11334: Split some field lists better Used by HighlightComponent and TermVectorComponent Used to produce an empty string on comma-space, leading to an exception.
David Smiley2af82c83d9cf
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex bd74c7ca681..97a00f285bf 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -127,6 +127,9 @@ Improvements* SOLR-14419: json.queries as well as other parameters might be referred via {"param":"ref"} in Query DSL (Mikhail Khludnev)+* SOLR-11334: hl.fl and tv.fl now parse field lists when they have both commas and spaces+ (David Smiley, Yasufumi Mizoguchi)+Optimizations---------------------* SOLR-8306: Do not collect expand documents when expand.rows=0 (Marshall Sanders, Amelia Henderson)diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.javaindex a255f01c14b..5bf6e17c91b 100644--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java@@ -196,19 +196,15 @@ public class SolrPluginUtils {}+ private static final Pattern SPLIT_PATTERN = Pattern.compile("[\\s,]+"); // space or comma----- private final static Pattern splitList=Pattern.compile(",| ");-- /** Split a value that may contain a comma, space of bar separated list. */- public static String[] split(String value){- return splitList.split(value.trim(), 0);+ /** Split a value between spaces and/or commas. No need to trim anything. */+ public static String[] split(String value) {+ // TODO consider moving / adapting this into a new StrUtils.splitSmart variant?+ // TODO deprecate; it's only used by two callers?+ return SPLIT_PATTERN.split(value.trim());}-/*** Pre-fetch documents into the index searcher's document cache.*diff --git a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.javaindex a77917bbeda..a21e197754c 100644--- a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java+++ b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java@@ -917,6 +917,24 @@ public class HighlighterTest extends SolrTestCaseJ4 {localRequest, new String[] {})));assertEquals(highlightedSetExpected, highlightedSetActual);}++ // SOLR-11334+ args.put("hl.fl", "title, text"); // comma then space+ lrf = h.getRequestFactory("", 0, 10, args);+ request = lrf.makeRequest("test");+ highlighter = HighlightComponent.getHighlighter(h.getCore());+ highlightFieldNames = Arrays.asList(highlighter.getHighlightFields(null,+ request, new String[] {}));+ assertEquals("Expected one field to highlight on", 2, highlightFieldNames+ .size());+ assertTrue("Expected to highlight on field \"title\"",+ highlightFieldNames.contains("title"));+ assertTrue("Expected to highlight on field \"text\"",+ highlightFieldNames.contains("text"));+ assertFalse("Expected to not highlight on field \"\"",+ highlightFieldNames.contains(""));++ request.close();}@Test