Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-7993: Raw json output for fields stopped working in 5.3.0 when requested fields do not include the unique key field name

Shalin Shekhar Mangarfe22692ad2a6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 598d8cde076..24849b130d1 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -291,7 +291,10 @@ Bug Fixes
* SOLR-8189: eTag calculation during HTTP Cache Validation uses unsynchronized WeakHashMap causing
threads to be stuck in runnable state. (shalin)
-
+
+* SOLR-7993: Raw json output for fields stopped working in 5.3.0 when requested fields do not include
+ the unique key field name. (Bill Bell, Ryan McKinley via shalin)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java b/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java
index a1462db3c7d..374a0db900d 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java
@@ -63,9 +63,9 @@ public abstract class DocTransformer {
public abstract void transform(SolrDocument doc, int docid, float score) throws IOException;
/**
- * When a transformer needs access to fields that are not automaticaly derived from the
+ * When a transformer needs access to fields that are not automatically derived from the
* input fields names, this option lets us explicitly say the field names that we hope
- * will be in the SolrDocument. These fields will be requestd from the
+ * will be in the SolrDocument. These fields will be requested from the
* {@link SolrIndexSearcher} but may or may not be returned in the final
* {@link QueryResponseWriter}
*
diff --git a/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java
index 8abb0502116..5e1f81a244b 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java
@@ -124,6 +124,11 @@ public class RawValueTransformerFactory extends TransformerFactory
doc.setField(display, new WriteableStringValue(val));
}
}
+
+ @Override
+ public String[] getExtraRequestFields() {
+ return new String[] {this.field};
+ }
}
public static class WriteableStringValue extends WriteableValue {
diff --git a/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java
new file mode 100644
index 00000000000..d8b66fd5104
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java
@@ -0,0 +1,71 @@
+package org.apache.solr.response;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.request.SolrQueryRequest;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests Raw JSON output for fields when used with and without the unique key field.
+ *
+ * See SOLR-7993
+ */
+public class TestRawTransformer extends SolrTestCaseJ4 {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-doctransformers.xml", "schema.xml");
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ assertU(delQ("*:*"));
+ assertU(commit());
+ }
+
+ @Test
+ public void testCustomTransformer() throws Exception {
+ // Build a simple index
+ int max = 10;
+ for (int i = 0; i < max; i++) {
+ SolrInputDocument sdoc = new SolrInputDocument();
+ sdoc.addField("id", i);
+ sdoc.addField("subject", "{poffL:[{offL:[{oGUID:\"79D5A31D-B3E4-4667-B812-09DF4336B900\",oID:\"OO73XRX\",prmryO:1,oRank:1,addTp:\"Office\",addCd:\"AA4GJ5T\",ad1:\"102 S 3rd St Ste 100\",city:\"Carson City\",st:\"MI\",zip:\"48811\",lat:43.176885,lng:-84.842919,phL:[\"(989) 584-1308\"],faxL:[\"(989) 584-6453\"]}]}]}");
+ sdoc.addField("title", "title_" + i);
+ updateJ(jsonAdd(sdoc), null);
+ }
+ assertU(commit());
+ assertQ(req("q", "*:*"), "//*[@numFound='" + max + "']");
+
+ SolrQueryRequest req = req("q", "*:*", "fl", "subject:[json]", "wt", "json");
+ String strResponse = h.query(req);
+ assertTrue("response does not contain right JSON encoding: " + strResponse,
+ strResponse.contains("\"subject\":[{poffL:[{offL:[{oGUID:\"7"));
+
+ req = req("q", "*:*", "fl", "id,subject", "wt", "json");
+ strResponse = h.query(req);
+ assertTrue("response does not contain right JSON encoding: " + strResponse,
+ strResponse.contains("subject\":[\""));
+ }
+
+}
+