nick-boss-tech commented on code in PR #5298:
URL: https://github.com/apache/solr/pull/5298#discussion_r4678917274
##########
solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java:
##########
@@ -346,10 +352,21 @@ public void process(ResponseBuilder rb) throws
IOException {
if (docid < 0) continue;
- SolrDocumentFetcher docFetcher =
searcherInfo.getSearcher().getDocFetcher();
- Document luceneDocument =
- docFetcher.doc(docid, rsp.getReturnFields().getLuceneFieldNames());
- SolrDocument doc = toSolrDoc(luceneDocument,
searcherInfo.getSearcher().getSchema());
+ SolrIndexSearcher searcher = searcherInfo.getSearcher();
+ @SuppressWarnings("ReferenceEquality") // cache key is the searcher
instance
+ final boolean searcherChanged = docFetcher == null || searcher !=
fieldSelectionSearcher;
+ if (searcherChanged) {
+ fieldSelectionSearcher = searcher;
+ docFetcher = searcher.getDocFetcher();
+ storedFields =
+ useLegacyStoredFields
+ ? returnFields.getLuceneFieldNames()
+ : docFetcher.getStoredFieldsToLoad(returnFields);
Review Comment:
Reworked: the stored fields to load are now computed once per searcher with
getStoredFieldsToLoad, toSolrDoc receives returnFields only on the normal path,
and when a transformer requires the full document for RTG the requested Lucene
field names are loaded with no returnFields filtering applied.
##########
solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java:
##########
@@ -229,31 +229,33 @@ public static void optimizePreFetchDocs(
}
ReturnFields returnFields = res.getReturnFields();
- if (returnFields.getLuceneFieldNames() != null) {
- Set<String> fieldFilter = returnFields.getLuceneFieldNames();
-
- if (rb.doHighlights) {
- // copy return fields list
- fieldFilter = new HashSet<>(fieldFilter);
- // add highlight fields
-
- HighlightComponent hl =
- (HighlightComponent)
-
req.getCore().getSearchComponents().get(HighlightComponent.COMPONENT_NAME);
- SolrHighlighter highlighter = hl.getHighlighter(req.getParams());
- Collections.addAll(fieldFilter, highlighter.getHighlightFields(query,
req, null));
-
- // fetch unique key if one exists.
- SchemaField keyField = searcher.getSchema().getUniqueKeyField();
- if (null != keyField) fieldFilter.add(keyField.getName());
- }
+ SolrDocumentFetcher docFetcher = searcher.getDocFetcher();
+ Set<String> fieldFilter =
docFetcher.getStoredFieldsToPrefetch(returnFields);
+ if (fieldFilter == null) {
+ return;
+ }
- // get documents
- SolrDocumentFetcher docFetcher = searcher.getDocFetcher();
- DocIterator iter = docs.iterator();
- for (int i = 0; i < docs.size(); i++) {
- docFetcher.doc(iter.nextDoc(), fieldFilter);
- }
+ if (rb.doHighlights) {
+ HighlightComponent hl =
+ (HighlightComponent)
+
req.getCore().getSearchComponents().get(HighlightComponent.COMPONENT_NAME);
+ SolrHighlighter highlighter = hl.getHighlighter(req.getParams());
+ Collections.addAll(fieldFilter, highlighter.getHighlightFields(query,
req, null));
+
+ // fetch unique key if one exists.
+ SchemaField keyField = searcher.getSchema().getUniqueKeyField();
+ if (null != keyField) fieldFilter.add(keyField.getName());
+ }
+
+ // A glob may match no stored fields or need only DocValues. Check after
highlighting has
Review Comment:
This works now: with the early return gone, a glob-only selection reaches
getStoredFieldsToPrefetch, which resolves the glob against the stored fields,
and the new tests in TestPseudoReturnFields cover it.
##########
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:
Moved back: getStoredFieldsToLoad and getStoredFieldsToPrefetch sit at the
end of the class again, where calcStoredFieldsForReturn was.
##########
changelog/unreleased/SOLR-18608-glob-rtg-prefetch.yml:
##########
@@ -0,0 +1,7 @@
+title: Honor glob field selection in real-time get and lazy document prefetch
+type: changed
Review Comment:
Changed the changelog type to `changed`.
##########
solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java:
##########
@@ -229,31 +229,33 @@ public static void optimizePreFetchDocs(
}
ReturnFields returnFields = res.getReturnFields();
- if (returnFields.getLuceneFieldNames() != null) {
- Set<String> fieldFilter = returnFields.getLuceneFieldNames();
-
- if (rb.doHighlights) {
- // copy return fields list
- fieldFilter = new HashSet<>(fieldFilter);
- // add highlight fields
-
- HighlightComponent hl =
- (HighlightComponent)
-
req.getCore().getSearchComponents().get(HighlightComponent.COMPONENT_NAME);
- SolrHighlighter highlighter = hl.getHighlighter(req.getParams());
- Collections.addAll(fieldFilter, highlighter.getHighlightFields(query,
req, null));
-
- // fetch unique key if one exists.
- SchemaField keyField = searcher.getSchema().getUniqueKeyField();
- if (null != keyField) fieldFilter.add(keyField.getName());
- }
+ SolrDocumentFetcher docFetcher = searcher.getDocFetcher();
+ Set<String> fieldFilter =
docFetcher.getStoredFieldsToPrefetch(returnFields);
+ if (fieldFilter == null) {
Review Comment:
Removed the early check as you suggested; the empty-filter case is now
handled after the highlight fields are added, so a glob that matches no stored
fields still skips the prefetch.
--
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]