You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2021/07/28 22:35:25 UTC

[lucene-solr] branch branch_8x updated: SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in from field

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

hossman 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 1e6e2dd  SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in from field
1e6e2dd is described below

commit 1e6e2ddc4212f0163567ede023d696338e6b2813
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Wed Jul 28 14:13:21 2021 -0700

    SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in from field
    
    (cherry picked from commit e7e80b1c5f6e900c11ca694e2cdc60667b788a06)
---
 solr/CHANGES.txt                                             |  2 ++
 .../apache/solr/search/join/CrossCollectionJoinQuery.java    |  4 +++-
 .../solr/search/join/CrossCollectionJoinQueryTest.java       | 12 ++++++++++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 14202fa..8daf752 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -50,6 +50,8 @@ Bug Fixes
 
 * SOLR-15531: SignificantTerms streaming function should not fail on empty collections (Benedikt Arnold via Mike Drob)
 
+* SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in "from" field (hossman)
+
 Other Changes
 ---------------------
 * SOLR-15355: Upgrade Hadoop from 3.2.0 to 3.2.2. (Antoine Gruzelle via David Smiley)
diff --git a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
index 465f82d..54d81bb 100644
--- a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
+++ b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java
@@ -294,7 +294,9 @@ public class CrossCollectionJoinQuery extends Query {
           }
 
           Object value = tuple.get(fromField);
-          collector.collect(value);
+          if (null != value) {
+            collector.collect(value);
+          }
         }
       } catch (IOException e) {
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
diff --git a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
index a42ebaa..cdfacb8 100644
--- a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
+++ b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java
@@ -20,6 +20,7 @@ package org.apache.solr.search.join;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
@@ -69,8 +70,6 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {
 
     buildIndexes(routeByKey);
 
-    assertResultCount("products", "*:*", NUM_PRODUCTS, true);
-    assertResultCount("parts", "*:*", NUM_PRODUCTS * 10 / 4, true);
   }
 
   private static void clearCollection(String collection) throws IOException, SolrServerException {
@@ -105,11 +104,20 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {
       }
     }
 
+    // some extra docs in each collection (not counded in NUM_PRODUCTS) that should drop out of the joins because they don't have the join key
+    productDocs.add(new SolrInputDocument("id", buildId(NUM_PRODUCTS+10, String.valueOf(NUM_PRODUCTS+10), routeByKey), "size_s", "M"));
+    partDocs.add(new SolrInputDocument("id", buildId(NUM_PRODUCTS+10, String.valueOf(NUM_PRODUCTS+10), routeByKey)));
+
+    Collections.shuffle(productDocs, random());
+    Collections.shuffle(partDocs, random());
+
     indexDocs("products", productDocs);
     cluster.getSolrClient().commit("products");
+    assertResultCount("products", "*:*", 1 + NUM_PRODUCTS, true);
 
     indexDocs("parts", partDocs);
     cluster.getSolrClient().commit("parts");
+    assertResultCount("parts", "*:*", 1 + (NUM_PRODUCTS * 10 / 4), true);
   }
 
   private static String buildId(int productId, String id, boolean routeByKey) {