You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2021/10/15 13:09:33 UTC
[lucene] branch main updated: LUCENE-10178 Add toString methond for
Lucene90HnswVectorsFormat (#383)
This is an automated email from the ASF dual-hosted git repository.
mayya pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new c9e56d2 LUCENE-10178 Add toString methond for Lucene90HnswVectorsFormat (#383)
c9e56d2 is described below
commit c9e56d27a3b88db2d9ba99477a778b298d8ff08c
Author: Mayya Sharipova <ma...@elastic.co>
AuthorDate: Fri Oct 15 09:09:27 2021 -0400
LUCENE-10178 Add toString methond for Lucene90HnswVectorsFormat (#383)
All toString method to Lucene90HnswVectorsFormat for testing
and debugging.
---
.../codecs/lucene90/Lucene90HnswVectorsFormat.java | 9 ++++++++
.../lucene90/TestLucene90HnswVectorsFormat.java | 27 ++++++++++++++++++++++
2 files changed, 36 insertions(+)
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.java
index 213e443..90875d9 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.java
index ae133bc..e13840b 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 BaseKnnVectorsFormatTestCase
protected 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));
+ }
}