lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [21/32] lucene-solr:jira/solr-12730: SOLR-7557: Fix parsing of child documents using queryAndStreamResponse
Date Mon, 29 Oct 2018 19:07:45 GMT
SOLR-7557: Fix parsing of child documents using queryAndStreamResponse


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6c419454
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6c419454
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6c419454

Branch: refs/heads/jira/solr-12730
Commit: 6c419454a23dd8149b4dc90f8e5ad9427a2750bd
Parents: 5c567d4
Author: Marvin Bredal Lillehaug <marvin.lillehaug@gmail.com>
Authored: Fri Oct 26 14:59:31 2018 +0200
Committer: Jan Høydahl <janhoy@apache.org>
Committed: Fri Oct 26 14:59:31 2018 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../impl/StreamingBinaryResponseParser.java     | 14 ++++-
 .../SolrExampleStreamingBinaryTest.java         | 56 ++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6c419454/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 03c97fd..1e0e530 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -212,6 +212,8 @@ Bug Fixes
 
 * SOLR-12868: Request forwarding for v2 API is broken (noble)
 
+* SOLR-7557: Fix parsing of child documents using queryAndStreamResponse (Marvin Bredal Lillehaug/Stian
Østerhaug via janhoy)
+
 Improvements
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6c419454/solr/solrj/src/java/org/apache/solr/client/solrj/impl/StreamingBinaryResponseParser.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/StreamingBinaryResponseParser.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/StreamingBinaryResponseParser.java
index 5f88672..b70daee 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/StreamingBinaryResponseParser.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/StreamingBinaryResponseParser.java
@@ -47,11 +47,21 @@ public class StreamingBinaryResponseParser extends BinaryResponseParser
{
   public NamedList<Object> processResponse(InputStream body, String encoding) {
     try (JavaBinCodec codec = new JavaBinCodec() {
 
+        private int nestedLevel;
+
         @Override
         public SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException
{
+          nestedLevel++;
           SolrDocument doc = super.readSolrDocument(dis);
-          callback.streamSolrDocument( doc );
-          return null;
+          nestedLevel--;
+          if (nestedLevel == 0) {
+            // parent document
+            callback.streamSolrDocument(doc);
+            return null;
+          } else {
+            // child document
+            return doc;
+          }
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6c419454/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingBinaryTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingBinaryTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingBinaryTest.java
index 1428054..bcab567 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingBinaryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingBinaryTest.java
@@ -16,12 +16,21 @@
  */
 package org.apache.solr.client.solrj.embedded;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.StreamingResponseCallback;
 import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
 import org.apache.solr.client.solrj.impl.BinaryResponseParser;
 import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.Test;
 
 @Slow
 @SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
@@ -34,4 +43,51 @@ public class SolrExampleStreamingBinaryTest extends SolrExampleStreamingTest
{
     client.setRequestWriter(new BinaryRequestWriter());
     return client;
   }
+
+  @Test
+  public void testQueryAndStreamResponse() throws Exception {
+    // index a simple document with one child
+    SolrClient client = getSolrClient();
+    client.deleteByQuery("*:*");
+
+    SolrInputDocument child = new SolrInputDocument();
+    child.addField("id", "child");
+    child.addField("type_s", "child");
+    child.addField("text_s", "text");
+
+    SolrInputDocument parent = new SolrInputDocument();
+    parent.addField("id", "parent");
+    parent.addField("type_s", "parent");
+    parent.addChildDocument(child);
+
+    client.add(parent);
+    client.commit();
+
+    // create a query with child doc transformer
+    SolrQuery query = new SolrQuery("{!parent which='type_s:parent'}text_s:text");
+    query.addField("*,[child parentFilter='type_s:parent']");
+
+    // test regular query
+    QueryResponse response = client.query(query);
+    assertEquals(1, response.getResults().size());
+    SolrDocument parentDoc = response.getResults().get(0);
+    assertEquals(1, parentDoc.getChildDocumentCount());
+
+    // test streaming
+    final List<SolrDocument> docs = new ArrayList<>();
+    client.queryAndStreamResponse(query, new StreamingResponseCallback() {
+      @Override
+      public void streamSolrDocument(SolrDocument doc) {
+        docs.add(doc);
+      }
+
+      @Override
+      public void streamDocListInfo(long numFound, long start, Float maxScore) {
+      }
+    });
+
+    assertEquals(1, docs.size());
+    parentDoc = docs.get(0);
+    assertEquals(1, parentDoc.getChildDocumentCount());
+  }
 }


Mime
View raw message