From 61ef031f7fa3abdd7c8c2f36db71ad2289b66131 Mon Sep 17 00:00:00 2001 From: Michael Sokolov Date: Mon, 29 Aug 2022 11:49:52 -0400 Subject: [PATCH] SimpleText knn vectors; fix searchExhaustively and suppress a byte format test case (#11725) --- .../codecs/simpletext/SimpleTextKnnVectorsReader.java | 6 +++--- .../core/src/test/org/apache/lucene/document/TestField.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextKnnVectorsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextKnnVectorsReader.java index e4b0ceb5916..10700f5de6f 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextKnnVectorsReader.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextKnnVectorsReader.java @@ -41,7 +41,6 @@ import org.apache.lucene.store.BufferedChecksumIndexInput; import org.apache.lucene.store.ChecksumIndexInput; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; -import org.apache.lucene.util.BitSet; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -187,8 +186,9 @@ public class SimpleTextKnnVectorsReader extends KnnVectorsReader { @Override public TopDocs searchExhaustively( String field, float[] target, int k, DocIdSetIterator acceptDocs) throws IOException { - int numDocs = (int) acceptDocs.cost(); - return search(field, target, k, BitSet.of(acceptDocs, numDocs), Integer.MAX_VALUE); + FieldInfo info = readState.fieldInfos.fieldInfo(field); + VectorSimilarityFunction vectorSimilarity = info.getVectorSimilarityFunction(); + return exhaustiveSearch(getVectorValues(field), acceptDocs, vectorSimilarity, target, k); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.java index 781f2b613c6..6aa5518f33b 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestField.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java @@ -20,6 +20,7 @@ import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS; import java.io.StringReader; import java.nio.charset.StandardCharsets; +import org.apache.lucene.codecs.Codec; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; @@ -513,6 +514,9 @@ public class TestField extends LuceneTestCase { } public void testKnnVectorField() throws Exception { + if (Codec.getDefault().getName().equals("SimpleText")) { + return; + } try (Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig())) { Document doc = new Document();