dsmiley commented on code in PR #5298:
URL: https://github.com/apache/solr/pull/5298#discussion_r4791632725


##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -905,10 +904,9 @@ private SolrDocument getSolrDoc(int luceneDocId) {
   public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
     final Set<String> storedFields = new HashSet<>();
     Set<String> fnames = returnFields.getLuceneFieldNames();
-    if 
(FullDocumentTransformer.requiresFullDocument(returnFields.getTransformer())) {
-      // The transformer reads fields that cannot be determined in advance, so 
load the full
-      // requested field set rather than the filtered one.
-      return fnames == null ? null : new HashSet<>(fnames);
+    if (returnFields.loadsAllFields()) {
+      // A transformer declared it needs the full document, so load every 
stored field.

Review Comment:
   There may be other reasons why; I wouldn't bother listing reasons.  i.e. 
simply `fl=*` would, I think. also mean loadsAllFiels, right?



##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -905,10 +904,9 @@ private SolrDocument getSolrDoc(int luceneDocId) {
   public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
     final Set<String> storedFields = new HashSet<>();
     Set<String> fnames = returnFields.getLuceneFieldNames();
-    if 
(FullDocumentTransformer.requiresFullDocument(returnFields.getTransformer())) {
-      // The transformer reads fields that cannot be determined in advance, so 
load the full
-      // requested field set rather than the filtered one.
-      return fnames == null ? null : new HashSet<>(fnames);
+    if (returnFields.loadsAllFields()) {

Review Comment:
   this early return can be the first line of the method; no sense in 
getting/declaring other things.



##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -905,10 +904,9 @@ private SolrDocument getSolrDoc(int luceneDocId) {
   public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
     final Set<String> storedFields = new HashSet<>();
     Set<String> fnames = returnFields.getLuceneFieldNames();
-    if 
(FullDocumentTransformer.requiresFullDocument(returnFields.getTransformer())) {
-      // The transformer reads fields that cannot be determined in advance, so 
load the full
-      // requested field set rather than the filtered one.
-      return fnames == null ? null : new HashSet<>(fnames);
+    if (returnFields.loadsAllFields()) {
+      // A transformer declared it needs the full document, so load every 
stored field.
+      return null;
     }
     if (returnFields.returnsAllFields()) {

Review Comment:
   if we return all fields, shouldn't it also be true that loadsAllFields?



##########
solr/core/src/java/org/apache/solr/search/SolrReturnFields.java:
##########
@@ -528,9 +533,27 @@ public boolean hasPatternMatching() {
     return !globs.isEmpty();
   }
 
+  /**
+   * Records the fields a transformer asked to have loaded. A return of 
exactly {@link
+   * DocTransformer#ALL_FIELDS} is not a field name; it declares that the 
transformer needs the full
+   * document, which {@link #loadsAllFields()} and {@link #loadsField(String)} 
then honor.
+   */
+  private void addExtraRequestFields(String[] extraRequestFields) {
+    if (Arrays.equals(extraRequestFields, DocTransformer.ALL_FIELDS)) {
+      loadAllFields = true;
+    } else {
+      Collections.addAll(loadFields, extraRequestFields);
+    }
+  }
+
+  @Override
+  public boolean loadsAllFields() {
+    return loadAllFields;
+  }
+
   @Override
   public boolean loadsField(String field) {
-    if (_returnAllFields || loadFields.contains(field)) {
+    if (_returnAllFields || loadAllFields || loadFields.contains(field)) {

Review Comment:
   if we change the logic so that `loadAllFields` means what a person would 
naturally think it means, (i.e. for `fl=*`), then this simplified to only check 
`loadAllFields` without bothering looking at `_returnAllFields`.



##########
solr/core/src/java/org/apache/solr/search/SolrReturnFields.java:
##########
@@ -58,6 +59,10 @@ public class SolrReturnFields extends ReturnFields {
   // This *may* include fields that will not be in the final response
   private final Set<String> loadFields = new HashSet<>();
 
+  // True when a transformer declared it needs the full document 
(DocTransformer.ALL_FIELDS);
+  // every stored field is then loaded, whatever loadFields holds

Review Comment:
   but that isn't the only reason we would "load all fields".  Surely we would 
as well when `fl=*` (the default)



##########
solr/core/src/java/org/apache/solr/search/ReturnFields.java:
##########
@@ -157,4 +157,13 @@ public boolean wantsScore() {
 
   /** Returns the DocTransformer used to modify documents, or 
<code>null</code> */
   public abstract DocTransformer getTransformer();
+
+  /**
+   * Returns <code>true</code> if a transformer has declared that it needs the 
full document (see
+   * {@link DocTransformer#ALL_FIELDS}), so every stored field should be 
loaded rather than only the
+   * requested ones.
+   */
+  public boolean loadsAllFields() {

Review Comment:
   probably make abstract and change the definition according to what I'm 
suggesting in my other comments on this PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to