dsmiley commented on code in PR #5298:
URL: https://github.com/apache/solr/pull/5298#discussion_r4795715542
##########
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);
Review Comment:
would you mind renaming `extraRequestFields` here to something with "Load"
and *not* "Request" in it ("Request" implies it should be returned)? I'm
thinking `transformerLoadFields`. WDYT? I know the current name is based on
the method name on the transformer but that name is unfortunate after recent
clarifications on the distinction between "load" and "request".
##########
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 _returnAllFields || loadAllFields;
Review Comment:
my point in my last feedback, not implemented, was proposing we make changes
to satisfy the following _invariant_ of the internal state: if
`_returnAllFields` is true, then `loadAllFields` is true as well. It would be
rather illogical to imagine otherwise just by looking at these names. Assuming
you understand my point/rationale, you could follow through with that, OR only
rename the `loadAllFields` field to narrowly mean what it currently actually
means (e.g. `transformerWantsToLoadAllFields`). I'm good with either way.
##########
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:
In a subtle way I was implying we need not have this condition, then.
##########
solr/core/src/java/org/apache/solr/search/SolrReturnFields.java:
##########
@@ -150,7 +155,7 @@ public SolrReturnFields(Collection<String> plainFields,
DocTransformer docTransf
// doc transformer can request extra fields.
String[] extraRequestFields = docTransformer.getExtraRequestFields();
if (extraRequestFields != null) {
- Collections.addAll(loadFields, extraRequestFields); // do NOT call
addField
+ addExtraRequestFields(extraRequestFields); // do NOT call addField
}
Review Comment:
minor: maybe just let addExtraRequestFields be null-safe so we can do a
one-liner in these various places without even needing to declare a variable.
Heck, we could just pass the transformer.
--
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]