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


##########
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:
   Done: the loadsAllFields check is now the first line of 
getStoredFieldsToLoad.



##########
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:
   Done: the reason comment is gone, and loadsAllFields now covers fl=* as well.



##########
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:
   Yes: loadsAllFields() now returns true whenever all fields are returned, so 
that case is covered by the first check.



##########
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:
   Right: loadsAllFields() now ORs in _returnAllFields, so fl=* counts too.



##########
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:
   Done: loadsField now checks only loadsAllFields() and loadFields.



##########
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:
   Done: loadsAllFields is abstract on ReturnFields now, with the wider 
definition.



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