jpountz commented on a change in pull request #534: URL: https://github.com/apache/lucene/pull/534#discussion_r768405655
########## File path: lucene/core/src/java/org/apache/lucene/index/EmptyKnnVectorsReader.java ########## @@ -0,0 +1,54 @@ +/* + * 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.codecs.KnnVectorsReader; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.util.Bits; + +/** Abstract base class implementing a {@link KnnVectorsReader} that has no vector values. */ +public abstract class EmptyKnnVectorsReader extends KnnVectorsReader { Review comment: We do it for doc values because doc values support 5 different types (numeric, sorted numeric, sorted, sorted set, binary) and the empty producer helps only implement the doc values type that we care about. Since there is a single type of vectors, I don't think we need this empty producer, let's remove it and extend KnnVectorsReader directly? ########## File path: lucene/core/src/java/org/apache/lucene/index/VectorValuesWriter.java ########## @@ -109,11 +110,15 @@ private void updateBytesUsed() { public void flush(Sorter.DocMap sortMap, KnnVectorsWriter knnVectorsWriter) throws IOException { VectorValues vectorValues = new BufferedVectorValues(docsWithField, vectors, fieldInfo.getVectorDimension()); - if (sortMap != null) { - knnVectorsWriter.writeField(fieldInfo, new SortingVectorValues(vectorValues, sortMap)); - } else { - knnVectorsWriter.writeField(fieldInfo, vectorValues); - } + KnnVectorsReader vectorsReader = + new EmptyKnnVectorsReader() { + @Override + public VectorValues getVectorValues(String field) throws IOException { + return sortMap != null ? new SortingVectorValues(vectorValues, sortMap) : vectorValues; Review comment: This is incorrect as it would return the same instance every time it is called. We should instantiate a new BufferedVectorValues instance every time this method is called. -- 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