Apache Lucene open-source search software
LUCENE-10178 Add toString methond for Lucene90HnswVectorsFormat (#383)
Mayya Sharipovac9e56d27a3b8
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsFormat.javaindex 213e443ba03..90875d9e3f5 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsFormat.java@@ -112,4 +112,13 @@ public final class Lucene90HnswVectorsFormat extends KnnVectorsFormat {public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {return new Lucene90HnswVectorsReader(state);}++ @Override+ public String toString() {+ return "Lucene90HnswVectorsFormat(name = Lucene90HnswVectorsFormat, maxConn = "+ + maxConn+ + ", beamWidth="+ + beamWidth+ + ")";+ }}diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90HnswVectorsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90HnswVectorsFormat.javaindex ae133bc58bb..e13840b97db 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90HnswVectorsFormat.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90HnswVectorsFormat.java@@ -16,7 +16,12 @@*/package org.apache.lucene.codecs.lucene90;+import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;+import static org.apache.lucene.codecs.lucene90.Lucene90HnswVectorsFormat.DEFAULT_BEAM_WIDTH;+import static org.apache.lucene.codecs.lucene90.Lucene90HnswVectorsFormat.DEFAULT_MAX_CONN;+import org.apache.lucene.codecs.Codec;+import org.apache.lucene.codecs.KnnVectorsFormat;import org.apache.lucene.index.BaseKnnVectorsFormatTestCase;import org.apache.lucene.util.TestUtil;@@ -25,4 +30,26 @@ public class TestLucene90HnswVectorsFormat extends BaseKnnVectorsFormatTestCaseprotected Codec getCodec() {return TestUtil.getDefaultCodec();}++ public void testToString() {+ int maxConn = randomIntBetween(DEFAULT_MAX_CONN - 10, DEFAULT_MAX_CONN + 10);+ int beamWidth = randomIntBetween(DEFAULT_BEAM_WIDTH - 50, DEFAULT_BEAM_WIDTH + 50);+ Codec customCodec =+ new Lucene90Codec() {+ @Override+ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {+ return new Lucene90HnswVectorsFormat(maxConn, beamWidth);+ }+ };+ String expectedString =+ "Lucene90HnswVectorsFormat(name = Lucene90HnswVectorsFormat, maxConn = "+ + maxConn+ + ", beamWidth="+ + beamWidth+ + ")";+ assert (((Lucene90Codec) customCodec)+ .getKnnVectorsFormatForField("bogus_field")+ .toString()+ .equals(expectedString));+ }}