Skip to content

Apache Lucene open-source search software

SOLR-2545: fix ExternalFileField / FileFloatSource so it can properly parse key=val pairs when the key contains an '=' char

Chris M. Hostetter2811c79bdb73
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 409395eddef..9483b8ac88f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -375,6 +375,11 @@ Bug Fixes
* SOLR-2642: Fixed sorting by function when using grouping. (Thomas Heigl, Martijn van Groningen)
+* SOLR-2545: ExternalFileField file parsing would fail if any key
+ contained an "=" character. It now only looks for the last "=" delimiter
+ prior to the float value.
+ (Markus Jelsma, hossman)
+
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java b/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java
index 7b265776df5..27b834bba4f 100755
--- a/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java
+++ b/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java
@@ -248,7 +248,7 @@ public class FileFloatSource extends ValueSource {
// final Bits liveDocs = MultiFields.getLiveDocs(reader);
for (String line; (line=r.readLine())!=null;) {
- int delimIndex = line.indexOf(delimiter);
+ int delimIndex = line.lastIndexOf(delimiter);
if (delimIndex < 0) continue;
int endIndex = line.length();
diff --git a/solr/core/src/test-files/solr/conf/schema11.xml b/solr/core/src/test-files/solr/conf/schema11.xml
index 0f0dd1bb180..adcc3518a57 100755
--- a/solr/core/src/test-files/solr/conf/schema11.xml
+++ b/solr/core/src/test-files/solr/conf/schema11.xml
@@ -239,6 +239,8 @@
<fieldType name="file" keyField="id" defVal="1" stored="false" indexed="false" class="solr.ExternalFileField" valType="float"/>
+ <fieldType name="sfile" keyField="sfile_s" defVal="1" stored="false" indexed="false" class="solr.ExternalFileField" valType="float"/>
+
<fieldType name="tint" class="solr.TrieIntField" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" omitNorms="true" positionIncrementGap="0"/>
@@ -340,6 +342,7 @@ valued. -->
<dynamicField name="*_ws" type="text_ws" indexed="true" stored="true"/>
<dynamicField name="*_extf" type="file"/>
+ <dynamicField name="*_extfs" type="sfile"/>
<dynamicField name="*_random" type="random" />
diff --git a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
index 38ab99ec539..2104741ce7a 100755
--- a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
+++ b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
@@ -283,6 +283,18 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
purgeFieldCache(FieldCache.DEFAULT); // avoid FC insanity
}
+ @Test
+ public void testExternalFileFieldStringKeys() throws Exception {
+ final String extField = "foo_extfs";
+ final String keyField = "sfile_s";
+ assertU(adoc("id", "991", keyField, "AAA=AAA"));
+ assertU(adoc("id", "992", keyField, "BBB"));
+ assertU(adoc("id", "993", keyField, "CCC=CCC"));
+ assertU(commit());
+ makeExternalFile(extField, "AAA=AAA=543210\nBBB=-8\nCCC=CCC=250","UTF-8");
+ singleTest(extField,"\0",991,543210,992,-8,993,250);
+ }
+
@Test
public void testGeneral() throws Exception {
clearIndex();