SOLR-8858: SolrIndexSearcher#doc() completely ignores field filters unless lazy field loading is enabled.

This closes #47.
This commit is contained in:
Shalin Shekhar Mangar 2016-07-07 13:22:15 +05:30
parent 7743718d29
commit 24d6b78469
3 changed files with 26 additions and 14 deletions

View File

@ -128,6 +128,9 @@ Bug Fixes
is introduced (defaults to true) to send version ranges instead of individual versions for peer sync. is introduced (defaults to true) to send version ranges instead of individual versions for peer sync.
(Pushkar Raste, shalin) (Pushkar Raste, shalin)
* SOLR-8858: SolrIndexSearcher#doc() completely ignores field filters unless lazy field loading is enabled.
(Caleb Rackliffe, David Smiley, shalin)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -766,12 +766,22 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
} }
final DirectoryReader reader = getIndexReader(); final DirectoryReader reader = getIndexReader();
if (!enableLazyFieldLoading || fields == null) { if (fields != null) {
d = reader.document(i); if (enableLazyFieldLoading) {
final SetNonLazyFieldSelector visitor = new SetNonLazyFieldSelector(fields, reader, i);
reader.document(i, visitor);
d = visitor.doc;
} else if (documentCache == null) {
d = reader.document(i, fields);
} else {
// we do not pass the fields in this case because that would return an incomplete document which would
// be eventually cached. The alternative would be to read the stored fields twice; once with the fields
// and then without for caching leading to a performance hit
// see SOLR-8858 for related discussion
d = reader.document(i);
}
} else { } else {
final SetNonLazyFieldSelector visitor = new SetNonLazyFieldSelector(fields, reader, i); d = reader.document(i);
reader.document(i, visitor);
d = visitor.doc;
} }
if (documentCache != null) { if (documentCache != null) {

View File

@ -127,7 +127,7 @@ public class TestSubQueryTransformer extends SolrTestCaseJ4 {
//System.out.println("p "+peopleMultiplier+" d "+deptMultiplier); //System.out.println("p "+peopleMultiplier+" d "+deptMultiplier);
assertQ("subq1.fl is limited to single field", assertQ("subq1.fl is limited to single field",
req("q","name_s:(john nancy)", "indent","true", req("q","name_s:(john nancy)", "indent","true",
"fl","name_s_dv,depts:[subquery]", "fl","dept_ss_dv,name_s_dv,depts:[subquery]",
"rows","" + (2 * peopleMultiplier), "rows","" + (2 * peopleMultiplier),
"depts.q","{!term f=dept_id_s v=$row.dept_ss_dv}", "depts.q","{!term f=dept_id_s v=$row.dept_ss_dv}",
"depts.fl","text_t", "depts.fl","text_t",
@ -150,8 +150,8 @@ public class TestSubQueryTransformer extends SolrTestCaseJ4 {
} }
final String[] johnAndNancyParams = new String[]{"q","name_s:(john nancy)", "indent","true", final String[] johnAndNancyParams = new String[]{"q","name_s:(john nancy)", "indent","true",
"fl","name_s_dv,depts:[subquery]", "fl","dept_ss_dv,name_s_dv,depts:[subquery]",
"fl","depts_i:[subquery]", "fl","dept_i_dv,depts_i:[subquery]",
"rows","" + (2 * peopleMultiplier), "rows","" + (2 * peopleMultiplier),
"depts.q","{!term f=dept_id_s v=$row.dept_ss_dv}", "depts.q","{!term f=dept_id_s v=$row.dept_ss_dv}",
"depts.fl","text_t", "depts.fl","text_t",
@ -225,7 +225,7 @@ public class TestSubQueryTransformer extends SolrTestCaseJ4 {
} }
String[] john = new String[]{"q","name_s:john", "indent","true", String[] john = new String[]{"q","name_s:john", "indent","true",
"fl","name_s_dv,depts:[subquery]", "fl","dept_ss_dv,name_s_dv,depts:[subquery]",
"rows","" + (2 * peopleMultiplier), "rows","" + (2 * peopleMultiplier),
"depts.q","+{!term f=dept_id_s v=$row.dept_ss_dv}^=0 _val_:id_i", "depts.q","+{!term f=dept_id_s v=$row.dept_ss_dv}^=0 _val_:id_i",
"depts.fl","id", "depts.fl","id",
@ -277,10 +277,10 @@ public class TestSubQueryTransformer extends SolrTestCaseJ4 {
assertQ("dave works at both dept with other folks", assertQ("dave works at both dept with other folks",
// System.out.println(h.query( // System.out.println(h.query(
req(new String[]{"q","name_s:dave", "indent","true", req(new String[]{"q","name_s:dave", "indent","true",
"fl","name_s_dv,subq1:[subquery]", "fl","dept_ss_dv,name_s_dv,subq1:[subquery]",
"rows","" + peopleMultiplier, "rows","" + peopleMultiplier,
"subq1.q","{!terms f=dept_id_s v=$row.dept_ss_dv}", "subq1.q","{!terms f=dept_id_s v=$row.dept_ss_dv}",
"subq1.fl","text_t,dept_id_s_dv,neighbours:[subquery]", "subq1.fl","dept_id_i_dv,text_t,dept_id_s_dv,neighbours:[subquery]",
"subq1.indent","true", "subq1.indent","true",
"subq1.rows",""+(deptMultiplier*2), "subq1.rows",""+(deptMultiplier*2),
"subq1.neighbours.q",//flipping via numbers "subq1.neighbours.q",//flipping via numbers
@ -459,9 +459,8 @@ public class TestSubQueryTransformer extends SolrTestCaseJ4 {
assertQ("dave works at both, whether we set a default separator or both", assertQ("dave works at both, whether we set a default separator or both",
req(new String[]{"q","name_s:dave", "indent","true", req(new String[]{"q","name_s:dave", "indent","true",
"fl",(random().nextBoolean() ? "name_s_dv" : "*")+ //"dept_ss_dv, "fl", (random().nextBoolean() ? "name_s_dv,dept_ss_dv" : "*") +
",subq1:[subquery " ",subq1:[subquery " +((random1.nextBoolean() ? "" : "separator=,"))+"]",
+((random1.nextBoolean() ? "" : "separator=,"))+"]",
"rows","" + peopleMultiplier, "rows","" + peopleMultiplier,
"subq1.q","{!terms f=dept_id_s v=$row.dept_ss_dv "+((random1.nextBoolean() ? "" : "separator=,"))+"}", "subq1.q","{!terms f=dept_id_s v=$row.dept_ss_dv "+((random1.nextBoolean() ? "" : "separator=,"))+"}",
"subq1.fl","text_t", "subq1.fl","text_t",