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

[solr] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new e7e80b1  SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in from field
e7e80b1 is described below

commit e7e80b1c5f6e900c11ca694e2cdc60667b788a06
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
---
 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 a5d5293..df24a7d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -394,6 +394,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
 ---------------------
 (No changes)
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 adf5dd0..272f777 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
@@ -292,7 +292,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 83d79b8..a976c99 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;
 
@@ -68,8 +69,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 {
@@ -104,11 +103,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) {