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/18 21:28:29 UTC

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

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



##########
File path: lucene/core/src/java/org/apache/lucene/index/IndexReader.java
##########
@@ -307,8 +307,21 @@ public final int hashCode() {
   /**
    * Retrieve term vectors for this document, or null if term vectors were not indexed. The returned
    * Fields instance acts like a single-document inverted index (the docID will be 0).
+   *
+   * @deprecated Use {@link IndexReader#getTermVectorsReader} instead.
    */
-  public abstract Fields getTermVectors(int docID) throws IOException;
+  @Deprecated
+  public final Fields getTermVectors(int docID) throws IOException {
+    TermVectors termVectors = getTermVectorsReader();
+    if (termVectors != null) {
+      return termVectors.get(docID);
+    }
+    return null;
+  }
+  ;
+
+  /** Get TermVectors from this index, or null if term vectors were not indexed. */
+  public abstract TermVectors getTermVectorsReader();

Review comment:
       This naming feels weird to me that it returns TV not TVR.

##########
File path: lucene/core/src/java/org/apache/lucene/index/TermVectors.java
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+
+/** Index API to access TermVectors */
+public abstract class TermVectors {

Review comment:
       This should probably be an interface?

##########
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'm not sure why but this scares me a little bit. Feels like there's a potential for more garbage than we currently get on the heap. I haven't measured anything though, so maybe it's ok?

##########
File path: lucene/core/src/java/org/apache/lucene/index/TermVectors.java
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+
+/** Index API to access TermVectors */
+public abstract class TermVectors {

Review comment:
       I’m really curious about the disadvantages you see with an interface versus an class with every method abstract. Can you give some hints so that I can do further research?




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

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