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/06/21 07:22:23 UTC

[solr] branch jira/solr16812_strref created (now c87a6534bfe)

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

noble pushed a change to branch jira/solr16812_strref
in repository https://gitbox.apache.org/repos/asf/solr.git


      at c87a6534bfe Support toggling STRREF feauture. It's a relatively new feature and it may not be supported on all platforms

This branch includes the following new commits:

     new c87a6534bfe Support toggling STRREF feauture. It's a relatively new feature and it may not be supported on all platforms

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[solr] 01/01: Support toggling STRREF feauture. It's a relatively new feature and it may not be supported on all platforms

Posted by no...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c87a6534bfecace764c92c41c084224c0a019376
Author: Noble Paul <no...@gmail.com>
AuthorDate: Wed Jun 21 17:22:05 2023 +1000

    Support toggling STRREF feauture. It's a relatively new feature and it may not be supported on all platforms
---
 .../java/org/apache/solr/handler/loader/CborLoader.java    |  2 +-
 .../java/org/apache/solr/response/CborResponseWriter.java  |  8 ++++++--
 .../src/test/org/apache/solr/util/TestCborDataFormat.java  | 14 ++++++++++++--
 .../modules/query-guide/pages/response-writers.adoc        |  4 +++-
 4 files changed, 22 insertions(+), 6 deletions(-)

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 f1ab9e24a34..ab6dfaf8fa0 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
@@ -127,7 +127,7 @@ public class CborLoader {
   }
 
   public static ContentStreamLoader createLoader(SolrParams p) {
-    CBORFactory factory = new CBORFactory();
+    CBORFactory factory = CBORFactory.builder().enable(CBORGenerator.Feature.STRINGREF).build();
     return new ContentStreamLoader() {
       @Override
       public void load(
diff --git a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java
index 9dbd2370112..294cba59851 100644
--- a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java
@@ -32,15 +32,19 @@ import org.apache.solr.request.SolrQueryRequest;
  */
 public class CborResponseWriter extends BinaryResponseWriter {
   final CBORFactory cborFactory;
+  final CBORFactory cborFactoryCompact;
 
   public CborResponseWriter() {
-    cborFactory = CBORFactory.builder().enable(CBORGenerator.Feature.STRINGREF).build();
+    cborFactoryCompact = CBORFactory.builder().enable(CBORGenerator.Feature.STRINGREF).build();
+    cborFactory = CBORFactory.builder().build();
   }
 
   @Override
   public void write(OutputStream out, SolrQueryRequest req, SolrQueryResponse response)
       throws IOException {
-    WriterImpl writer = new WriterImpl(cborFactory, out, req, response);
+    boolean useStringRef = req.getParams().getBool("string_ref", true);
+    WriterImpl writer =
+        new WriterImpl(useStringRef ? cborFactoryCompact : cborFactory, out, req, response);
     writer.writeResponse();
     writer.gen.flush();
   }
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 4caa6ebd15a..90b61853bfb 100644
--- a/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
+++ b/solr/core/src/test/org/apache/solr/util/TestCborDataFormat.java
@@ -87,6 +87,9 @@ public class TestCborDataFormat extends SolrCloudTestCase {
       runQuery(testCollection, client, "json");
       runQuery(testCollection, client, "json");
       b = runQuery(testCollection, client, "cbor");
+      int compactSz = b.length;
+      b = runQuery(testCollection, client, "cbor-noncompact");
+      assertTrue(compactSz < b.length);
       b = runQuery(testCollection, client, "cbor");
       ObjectMapper objectMapper = new ObjectMapper(new CBORFactory());
       Object o = objectMapper.readValue(b, Object.class);
@@ -116,11 +119,18 @@ public class TestCborDataFormat extends SolrCloudTestCase {
     NamedList<Object> result;
     QueryRequest request;
     RTimer timer = new RTimer();
-    request = new QueryRequest(new SolrQuery("*:*").setRows(1111));
-    request.setResponseParser(new InputStreamResponseParser(wt));
+    SolrQuery q = new SolrQuery("*:*").setRows(1111);
+    request = new QueryRequest(q);
+    if (wt.equals("cbor-noncompact")) {
+      q.set("string_ref", false);
+      request.setResponseParser(new InputStreamResponseParser("cbor"));
+    } else {
+      request.setResponseParser(new InputStreamResponseParser(wt));
+    }
     result = client.request(request, testCollection);
     byte[] b = copyStream((InputStream) result.get("stream"));
     System.out.println(wt + "_time : " + timer.getTime());
+    System.out.println(wt + "_size : " + b.length);
     return b;
   }
 
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc b/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
index bbc08e04478..6fc40c65ef7 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
@@ -397,7 +397,9 @@ MA147LL/A,"electronics,music",Apple 60 GB iPod with Video Playback Black,10,399.
 
 == CBOR Response Writer
 
-Solr supports CBOR format which is more compact and fast.
+Solr supports CBOR response format which is more compact and fast. Use the `wt=cbor` parameter to get responses in CBOR.
+
+If your client does not support the STRINGREF feature of CBOR, use `wt=cbor&str_ref=false`
 
 === Example Python program