You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2020/10/14 12:28:54 UTC

[lucene-solr] branch branch_8x updated: SOLR-14869: ChildDocTransformer should have omitted deleted child documents. Closes #1970

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

dsmiley pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 1bbea05  SOLR-14869: ChildDocTransformer should have omitted deleted child documents. Closes #1970
1bbea05 is described below

commit 1bbea05ac774cc925a106ec5c3c070412620315b
Author: Bar Rotstein <ba...@gmail.com>
AuthorDate: Wed Oct 14 08:25:52 2020 -0400

    SOLR-14869: ChildDocTransformer should have omitted deleted child documents.
    Closes #1970
    
    (cherry picked from commit fa3e1ad71fd97200b98f9e7d1e461ddfa78e357c)
---
 solr/CHANGES.txt                                   |  2 +
 .../response/transform/ChildDocTransformer.java    | 11 ++++-
 .../TestChildDocTransformerHierarchy.java          | 47 ++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e8d3611..235e12e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -105,6 +105,8 @@ Optimizations
 Bug Fixes
 ---------------------
 
+* SOLR-14869: ChildDocTransformer should have omitted deleted child documents. (Bar Rotstein, David Smiley)
+
 * SOLR-11656: TLOG replication doesn't work properly after rebalancing leaders. (Yuki Yano via
   Erick Erickson)
 
diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformer.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformer.java
index 7339bf6..de00b82 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformer.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformer.java
@@ -32,6 +32,7 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.join.BitSetProducer;
+import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BitSet;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrException;
@@ -89,6 +90,7 @@ class ChildDocTransformer extends DocTransformer {
       final int segBaseId = leafReaderContext.docBase;
       final int segRootId = rootDocId - segBaseId;
       final BitSet segParentsBitSet = parentsFilter.getBitSet(leafReaderContext);
+      final Bits liveDocs = leafReaderContext.reader().getLiveDocs();
 
       if (segParentsBitSet == null) {
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
@@ -117,9 +119,16 @@ class ChildDocTransformer extends DocTransformer {
       int matches = 0;
       // Loop each child ID up to the parent (exclusive).
       for (int docId = firstChildId; docId < rootDocId; ++docId) {
+        final int segDocId = docId - segBaseId;
+
+        // check whether doc is "live"
+        if (liveDocs != null && !liveDocs.get(segDocId)) {
+          // doc is not "live"; return fast
+          continue;
+        }
 
         // get the path.  (note will default to ANON_CHILD_KEY if schema is not nested or empty string if blank)
-        final String fullDocPath = getPathByDocId(docId - segBaseId, segPathDocValues);
+        final String fullDocPath = getPathByDocId(segDocId, segPathDocValues);
 
         if (isNestedSchema && !fullDocPath.startsWith(rootDocPath)) {
           // is not a descendant of the transformed doc; return fast.
diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
index bda4e7d..02c1aca 100644
--- a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
+++ b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java
@@ -136,6 +136,53 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {
   }
 
   @Test
+  public void testWithDeletedChildren() throws Exception {
+    // add a doc to create another segment
+    final String addNonTestedDoc =
+        "{\n" +
+          "\"add\": {\n" +
+            "\"doc\": {\n" +
+                "\"id\": " + -1000 + ", \n" +
+                "\"type_s\": \"cake\", \n" +
+            "}\n" +
+          "}\n" +
+        "}";
+
+    if (random().nextBoolean()) {
+      updateJ(addNonTestedDoc, null);
+      assertU(commit());
+    }
+
+    indexSampleData(numberOfDocsPerNestedTest);
+    // delete toppings path
+    assertU(delQ("_nest_path_:\\/toppings"));
+    assertU(commit());
+
+    try(SolrQueryRequest req = req("q", "type_s:donut", "sort", "id asc", "fl", "id, type_s, toppings, _nest_path_, [child childFilter='_nest_path_:/toppings' limit=1]",
+        "fq", fqToExcludeNonTestedDocs)) {
+      BasicResultContext res = (BasicResultContext) h.queryAndResponse("/select", req).getResponse();
+      Iterator<SolrDocument> docsStreamer = res.getProcessedDocuments();
+      while (docsStreamer.hasNext()) {
+        SolrDocument doc = docsStreamer.next();
+        cleanSolrDocumentFields(doc);
+        assertFalse("root doc should not have anonymous child docs", doc.hasChildDocuments());
+        assertNull("should not include deleted docs", doc.getFieldValues("toppings"));
+      }
+    }
+
+    assertJQ(req("q", "type_s:donut",
+        "sort", "id asc",
+        "fl", "*, [child limit=1]",
+        "fq", fqToExcludeNonTestedDocs),
+        "/response/docs/[0]/type_s==donut",
+        "/response/docs/[0]/lonely/test_s==testing",
+        "/response/docs/[0]/lonely/lonelyGrandChild/test2_s==secondTest",
+        // "!" (negate): don't find toppings.  The "limit" kept us from reaching these, which follow lonely.
+        "!/response/docs/[0]/toppings/[0]/type_s==Regular"
+    );
+  }
+
+  @Test
   public void testChildFilterLimitJSON() throws Exception {
     indexSampleData(numberOfDocsPerNestedTest);