Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-11154: Child documents' return fields now include useDocValuesAsStored fields

Ishan Chattopadhyaya924b3fd47290
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cb436d42c3e..e5abb3bc3b7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -397,6 +397,9 @@ Bug Fixes
* SOLR-11151: SolrInfoMBeanHandler.getDiff() ADD case non-functional: NPE when a bean value goes from null -> non-null.
(Steve Rowe)
+* SOLR-11154: Child documents' return fields now include useDocValuesAsStored fields (Mohammed Sheeri Shaketi Nauage via
+ Ishan Chattopadhyaya)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
index 45b0efc6632..ff7c0614f3d 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
@@ -17,6 +17,7 @@
package org.apache.solr.response.transform;
import java.io.IOException;
+import java.util.Set;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexableField;
@@ -39,6 +40,7 @@ import org.apache.solr.search.DocList;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QueryWrapperFilter;
import org.apache.solr.search.SyntaxError;
+import org.apache.solr.search.SolrDocumentFetcher;
/**
*
@@ -135,12 +137,21 @@ class ChildDocTransformer extends DocTransformer {
Query query = new ToChildBlockJoinQuery(parentQuery, parentsFilter);
DocList children = context.getSearcher().getDocList(query, childFilterQuery, new Sort(), 0, limit);
if(children.matches() > 0) {
+ SolrDocumentFetcher docFetcher = context.getSearcher().getDocFetcher();
+
+ Set<String> dvFieldsToReturn = docFetcher.getNonStoredDVs(true);
+ boolean shouldDecorateWithDVs = dvFieldsToReturn.size() > 0;
DocIterator i = children.iterator();
+
while(i.hasNext()) {
Integer childDocNum = i.next();
Document childDoc = context.getSearcher().doc(childDocNum);
SolrDocument solrChildDoc = DocsStreamer.convertLuceneDocToSolrDoc(childDoc, schema);
+ if (shouldDecorateWithDVs) {
+ docFetcher.decorateDocValueFields(solrChildDoc, childDocNum, dvFieldsToReturn);
+ }
+
// TODO: future enhancement...
// support an fl local param in the transformer, which is used to build
// a private ReturnFields instance that we use to prune unwanted field
diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformer.java b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformer.java
index 2e68d78653d..71b77f44b2a 100644
--- a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformer.java
+++ b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformer.java
@@ -59,6 +59,8 @@ public class TestChildDocTransformer extends SolrTestCaseJ4 {
testSubQueryXML();
testSubQueryJSON();
+
+ testChildDocNonStoredDVFields();
}
private void testChildDoctransformerXML() {
@@ -205,6 +207,36 @@ public class TestChildDocTransformer extends SolrTestCaseJ4 {
"/response/docs/[0]/_childDocuments_/[1]/id=='5'"
};
+ assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ",
+ "fl", "*,[child parentFilter=\"subject:parentDocument\"]"), test1);
+
+ assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ",
+ "fl", "subject,[child parentFilter=\"subject:parentDocument\" childFilter=\"title:foo\"]"), test2);
+
+ assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ",
+ "fl", "subject,[child parentFilter=\"subject:parentDocument\" childFilter=\"title:bar\" limit=2]"), test3);
+ }
+
+ private void testChildDocNonStoredDVFields() throws Exception {
+ String[] test1 = new String[] {
+ "/response/docs/[0]/_childDocuments_/[0]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[1]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[2]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[3]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[4]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[5]/intDvoDefault==42"
+ };
+
+ String[] test2 = new String[] {
+ "/response/docs/[0]/_childDocuments_/[0]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[1]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[2]/intDvoDefault==42"
+ };
+
+ String[] test3 = new String[] {
+ "/response/docs/[0]/_childDocuments_/[0]/intDvoDefault==42",
+ "/response/docs/[0]/_childDocuments_/[1]/intDvoDefault==42"
+ };
assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ",
"fl", "*,[child parentFilter=\"subject:parentDocument\"]"), test1);
@@ -214,6 +246,7 @@ public class TestChildDocTransformer extends SolrTestCaseJ4 {
assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ",
"fl", "subject,[child parentFilter=\"subject:parentDocument\" childFilter=\"title:bar\" limit=2]"), test3);
+
}
private void createSimpleIndex() {