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

This commit is contained in:
Ishan Chattopadhyaya 2017-07-30 02:43:36 +05:30
parent 232fb33fd1
commit 924b3fd472
3 changed files with 47 additions and 0 deletions

View File

@ -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
----------------------

View File

@ -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

View File

@ -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() {