Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15531: Cross-collection join fixed to ignore documents that do not contain value in from field

Chris Hostettere7e80b1c5f6e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a5d5293aaeb..df24a7daf33 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 adf5dd08b8b..272f7778432 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 83d79b875c1..a976c9993e5 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) {