You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2023/08/17 14:17:15 UTC

[solr] branch branch_9x updated: SOLR-16939: CBOR format should support nested documents (#1845)

This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 867cefd8066 SOLR-16939: CBOR format should support nested documents (#1845)
867cefd8066 is described below

commit 867cefd8066c9cfb8beb7f75693a4be7a038c36a
Author: Noble Paul <no...@users.noreply.github.com>
AuthorDate: Fri Aug 18 00:14:21 2023 +1000

    SOLR-16939: CBOR format should support nested documents (#1845)
---
 .../org/apache/solr/handler/loader/CborLoader.java |  5 +++
 .../cloud-managed/conf/managed-schema.xml          |  2 +
 .../org/apache/solr/util/TestCborDataFormat.java   | 50 ++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/solr/core/src/java/org/apache/solr/handler/loader/CborLoader.java b/solr/core/src/java/org/apache/solr/handler/loader/CborLoader.java
index ab6dfaf8fa0..3f0f6067625 100644
--- a/solr/core/src/java/org/apache/solr/handler/loader/CborLoader.java
+++ b/solr/core/src/java/org/apache/solr/handler/loader/CborLoader.java
@@ -123,6 +123,11 @@ public class CborLoader {
     if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
       return p.getNumberValue();
     }
+    if (t == JsonToken.START_OBJECT) {
+      Object[] returnVal = new Object[1];
+      new CborLoader(cborFactory, d -> returnVal[0] = d).handleDoc(p);
+      return returnVal[0];
+    }
     throw new RuntimeException("Unknown type :" + t);
   }
 
diff --git a/solr/core/src/test-files/solr/configsets/cloud-managed/conf/managed-schema.xml b/solr/core/src/test-files/solr/configsets/cloud-managed/conf/managed-schema.xml
index 14e5b94fb67..a3176d2d412 100644
--- a/solr/core/src/test-files/solr/configsets/cloud-managed/conf/managed-schema.xml
+++ b/solr/core/src/test-files/solr/configsets/cloud-managed/conf/managed-schema.xml
@@ -39,6 +39,8 @@
 
     <!-- needed for splitByPrefix -->
   <field name="id_prefix" type="composite_id_prefix" indexed="true" stored="false"/>
+  <dynamicField name="*_s" type="string" indexed="true" stored="true"/>
+  <dynamicField name="*_i" type="int" indexed="true" stored="true"/>
   <copyField source="id" dest="id_prefix"/>
   <fieldtype name="composite_id_prefix" class="solr.TextField">
     <analyzer>
diff --git a/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java b/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
index 90b61853bfb..b24e649ce28 100644
--- a/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
+++ b/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
@@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.List;
@@ -42,6 +43,7 @@ import org.apache.solr.client.solrj.request.GenericSolrRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.client.solrj.request.RequestWriter;
 import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.cloud.MiniSolrCloudCluster;
 import org.apache.solr.cloud.SolrCloudTestCase;
 import org.apache.solr.common.params.MapSolrParams;
@@ -95,6 +97,15 @@ public class TestCborDataFormat extends SolrCloudTestCase {
       Object o = objectMapper.readValue(b, Object.class);
       List<Object> l = (List<Object>) Utils.getObjectByPath(o, false, "response/docs");
       assertEquals(1100, l.size());
+      client.deleteByQuery(testCollection, "*:*").getStatus();
+      index(
+          testCollection,
+          client,
+          createCborReq(getNestedDocs().getBytes(StandardCharsets.UTF_8)),
+          false);
+      SolrQuery q = new SolrQuery("*:*").setRows(100);
+      QueryResponse result = new QueryRequest(q).process(client, testCollection);
+      assertEquals(6, result.getResults().size());
     } finally {
       System.clearProperty("managed.schema.mutable");
       cluster.shutdown();
@@ -227,4 +238,43 @@ public class TestCborDataFormat extends SolrCloudTestCase {
     jsonGenerator.close();
     return baos.toByteArray();
   }
+
+  private String getNestedDocs() throws IOException {
+    return "[{ \"id\": \"P11!prod\",\n"
+        + "   \"name_s\": \"Swingline Stapler\",\n"
+        + "   \"type_s\": \"PRODUCT\",\n"
+        + "   \"description_s\": \"The Cadillac of office staplers ...\",\n"
+        + "   \"skus\": [\n"
+        + "       { \"id\": \"P11!S21\",\n"
+        + "         \"type_s\": \"SKU\",\n"
+        + "         \"color_s\": \"RED\",\n"
+        + "         \"price_i\": 42,\n"
+        + "         \"manuals\": [\n"
+        + "             { \"id\": \"P11!D41\",\n"
+        + "               \"type_s\": \"MANUAL\",\n"
+        + "               \"name_s\": \"Red Swingline Brochure\",\n"
+        + "               \"pages_i\":1,\n"
+        + "               \"content_s\": \"...\"\n"
+        + "             } ]\n"
+        + "       },\n"
+        + "       { \"id\": \"P11!S31\",\n"
+        + "         \"type_s\": \"SKU\",\n"
+        + "         \"color_s\": \"BLACK\",\n"
+        + "         \"price_i\": 3\n"
+        + "       },\n"
+        + "       { \"id\": \"P11!D51\",\n"
+        + "         \"type_s\": \"MANUAL\",\n"
+        + "         \"name_s\": \"Quick Reference Guide\",\n"
+        + "         \"pages_i\":1,\n"
+        + "         \"content_s\": \"How to use your stapler ...\"\n"
+        + "       },\n"
+        + "       { \"id\": \"P11!D61\",\n"
+        + "         \"type_s\": \"MANUAL\",\n"
+        + "         \"name_s\": \"Warranty Details\",\n"
+        + "         \"pages_i\":42,\n"
+        + "         \"content_s\": \"... lifetime guarantee ...\"\n"
+        + "       }\n"
+        + "    ]\n"
+        + "} ]";
+  }
 }