vigyasharma commented on code in PR #14373:
URL: https://github.com/apache/lucene/pull/14373#discussion_r2008971160


##########
lucene/core/src/java/org/apache/lucene/index/ParallelLeafReader.java:
##########
@@ -348,15 +348,24 @@ public void prefetch(int docID) throws IOException {
       @Override
       public Fields get(int docID) throws IOException {
         ParallelFields fields = null;
-        for (Map.Entry<String, LeafReader> ent : tvFieldToReader.entrySet()) {
-          String fieldName = ent.getKey();
-          TermVectors termVectors = readerToTermVectors.get(ent.getValue());
-          Terms vector = termVectors.get(docID, fieldName);
-          if (vector != null) {
-            if (fields == null) {
-              fields = new ParallelFields();
-            }
-            fields.addField(fieldName, vector);
+
+        // Step 2: Fetch all term vectors once per reader
+        for (Map.Entry<LeafReader, TermVectors> entry : 
readerToTermVectors.entrySet()) {
+          TermVectors termVectors = entry.getValue();
+          Fields docFields = termVectors.get(docID); // Fetch all fields at 
once
+
+          if (docFields != null) {
+              if (fields == null) {
+                  fields = new ParallelFields();
+              }
+
+              // Step 3: Aggregate only required fields
+              for (String fieldName : docFields) {
+                  Terms vector = docFields.terms(fieldName);
+                  if (vector != null) {

Review Comment:
   > `docFields.terms(fieldName)` can be null if the field exists in 
`docFields` but does not have term vectors stored.
   
   Okay. I thought `termVectors.get(docID)` only returns Fields that have terms.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to