You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/06/30 08:26:24 UTC

[GitHub] [lucene] zacharymorn commented on a change in pull request #180: LUCENE-9959: Add non thread local based API for term vector reader usage

zacharymorn commented on a change in pull request #180:
URL: https://github.com/apache/lucene/pull/180#discussion_r661242673



##########
File path: lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java
##########
@@ -112,10 +112,29 @@ protected BaseCompositeReader(R[] subReaders, Comparator<R> subReadersSorter) th
   }
 
   @Override
-  public final Fields getTermVectors(int docID) throws IOException {
-    ensureOpen();
-    final int i = readerIndex(docID); // find subreader num
-    return subReaders[i].getTermVectors(docID - starts[i]); // dispatch to subreader
+  public final TermVectors getTermVectorsReader() {
+    TermVectors[] termVectors = new TermVectors[subReaders.length];
+
+    // subReaders is a collection of segmentReaders
+    for (int i = 0; i < subReaders.length; i++) {
+      // the getTermVectorsReader would clone a new instance, hence saving it into an array
+      // to avoid re-cloning from direct subReaders[i].getTermVectorsReader() call
+      termVectors[i] = subReaders[i].getTermVectorsReader();
+    }
+
+    return new TermVectors() {

Review comment:
       I've implemented the lazy-init approach in the latest commit and it passed the existing tests (in particular, `TestMultiThreadTermVectors`), so I think it should be safe for threaded situation? One downside from this approach I see though is that since `null` was used to indicate both TV not available and not initialized, lazy-init will require repeated `subReaders[i].getTermVectorsReader()` calls to get TV reader in the same segment if that segment simply doesn't contain any TV index.




-- 
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-unsubscribe@lucene.apache.org

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



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