From 98b872e767b883efab069fb78161d8d07a6406d1 Mon Sep 17 00:00:00 2001 From: Mohammed Sheeri Shaketi Nauage Date: Wed, 26 Jul 2017 17:59:39 -0500 Subject: [PATCH] SOLR-11154: return useDocValuesAsStored fields in child documents --- .../transform/ChildDocTransformerFactory.java | 11 +++++++ .../transform/TestChildDocTransformer.java | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) 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 45b0efc66326..ff7c0614f3d0 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.QParser; import org.apache.solr.search.QueryWrapperFilter; import org.apache.solr.search.SyntaxError; +import org.apache.solr.search.SolrDocumentFetcher; /** * @@ -135,12 +137,21 @@ public void transform(SolrDocument doc, int docid, float score) { 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 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 2e68d78653d5..71b77f44b2a2 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 void testAllParams() throws Exception { testSubQueryXML(); testSubQueryJSON(); + + testChildDocNonStoredDVFields(); } private void testChildDoctransformerXML() { @@ -205,6 +207,36 @@ private void testChildDoctransformerJSON() throws Exception { "/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 @@ private void testChildDoctransformerJSON() throws Exception { assertJQ(req("q", "*:*", "fq", "subject:\"parentDocument\" ", "fl", "subject,[child parentFilter=\"subject:parentDocument\" childFilter=\"title:bar\" limit=2]"), test3); + } private void createSimpleIndex() {