nick-boss-tech commented on code in PR #5298:
URL: https://github.com/apache/solr/pull/5298#discussion_r4727407864


##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -931,4 +896,60 @@ private SolrDocument getSolrDoc(int luceneDocId) {
       return sdoc;
     }
   }
+
+  /**
+   * Returns the stored fields selected by the response and its transformers, 
before DocValues
+   * substitution. A null result means all stored fields; otherwise the 
returned set is mutable.
+   */
+  public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
+    final Set<String> storedFields = new HashSet<>();
+    Set<String> fnames = returnFields.getLuceneFieldNames();
+    if (returnFields.returnsAllFields()) {
+      return null;
+    } else if (returnFields.hasPatternMatching()) {
+      for (String s : getAllStored()) {
+        if (returnFields.loadsField(s)) {
+          storedFields.add(s);
+        }
+      }
+    } else if (fnames != null) {
+      storedFields.addAll(fnames);
+      storedFields.removeIf(
+          (String name) -> {
+            SchemaField schemaField = 
searcher.getSchema().getFieldOrNull(name);
+            if (schemaField == null) {
+              // Get it from the stored fields if, for some reason, we can't 
get the schema.
+              return false;
+            }
+            if (schemaField.stored() && schemaField.multiValued()) {
+              // must return multivalued fields from stored data if possible.
+              return false;
+            }
+            if (schemaField.stored() == false) {
+              // if it's not stored, no choice but to return from DV.
+              return true;
+            }
+            return false;
+          });
+    }
+    storedFields.remove(SolrReturnFields.SCORE);
+    return storedFields;
+  }
+
+  /**
+   * Returns a mutable field filter for prefetch, or null to skip prefetch. 
The filter holds the
+   * stored fields the selection needs loaded, cleared when DocValues can 
substitute for every one
+   * of them. An empty filter can still gain fields from highlighting.
+   */
+  public Set<String> getStoredFieldsToPrefetch(ReturnFields returnFields) {
+    Set<String> storedFields = getStoredFieldsToLoad(returnFields);

Review Comment:
   Done: explicit selections now go through getStoredFieldsToLoad like globs, 
and the empty-filter skip in optimizePreFetchDocs applies to them too; three 
new tests cover the DV-only, substitutable, and mixed explicit cases, and 
LargeFieldTest's setup loads its cache fixture directly since an all-DocValues 
explicit fl no longer warms the cache.



##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -931,4 +896,60 @@ private SolrDocument getSolrDoc(int luceneDocId) {
       return sdoc;
     }
   }
+
+  /**
+   * Returns the stored fields selected by the response and its transformers, 
before DocValues
+   * substitution. A null result means all stored fields; otherwise the 
returned set is mutable.
+   */
+  public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {

Review Comment:
   Thanks, that matches what I intended.



##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -931,4 +896,64 @@ private SolrDocument getSolrDoc(int luceneDocId) {
       return sdoc;
     }
   }
+
+  /**
+   * Returns the stored fields selected by the response and its transformers, 
before DocValues
+   * substitution. A null result means all stored fields; otherwise the 
returned set is mutable.
+   */
+  public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {
+    final Set<String> storedFields = new HashSet<>();
+    Set<String> fnames = returnFields.getLuceneFieldNames();
+    if (returnFields.returnsAllFields()) {
+      return null;
+    } else if (returnFields.hasPatternMatching()) {
+      for (String s : getAllStored()) {
+        if (returnFields.loadsField(s)) {
+          storedFields.add(s);
+        }
+      }
+    } else if (fnames != null) {
+      storedFields.addAll(fnames);
+      storedFields.removeIf(
+          (String name) -> {
+            SchemaField schemaField = 
searcher.getSchema().getFieldOrNull(name);
+            if (schemaField == null) {
+              // Get it from the stored fields if, for some reason, we can't 
get the schema.
+              return false;
+            }
+            if (schemaField.stored() && schemaField.multiValued()) {
+              // must return multivalued fields from stored data if possible.
+              return false;
+            }
+            if (schemaField.stored() == false) {
+              // if it's not stored, no choice but to return from DV.
+              return true;
+            }
+            return false;
+          });
+    }
+    storedFields.remove(SolrReturnFields.SCORE);
+    return storedFields;
+  }
+
+  /**
+   * Returns a mutable field filter for prefetch, or null to skip prefetch. 
Preserve the original
+   * explicit-field filter; only pattern selections expand stored fields and 
apply DocValues
+   * substitution. An empty pattern filter can still gain fields from 
highlighting.
+   */
+  public Set<String> getStoredFieldsToPrefetch(ReturnFields returnFields) {
+    if (!returnFields.hasPatternMatching()) {

Review Comment:
   Done: explicit selections now go through getStoredFieldsToLoad like globs, 
and the empty-filter skip in optimizePreFetchDocs applies to them too; three 
new tests cover the DV-only, substitutable, and mixed explicit cases, and 
LargeFieldTest's setup loads its cache fixture directly since an all-DocValues 
explicit fl no longer warms the cache.



##########
solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java:
##########
@@ -931,4 +896,64 @@ private SolrDocument getSolrDoc(int luceneDocId) {
       return sdoc;
     }
   }
+
+  /**
+   * Returns the stored fields selected by the response and its transformers, 
before DocValues
+   * substitution. A null result means all stored fields; otherwise the 
returned set is mutable.
+   */
+  public Set<String> getStoredFieldsToLoad(ReturnFields returnFields) {

Review Comment:
   Thanks, that matches what I intended.



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