LUCENE-10178 Add toString methond for Lucene90HnswVectorsFormat (#383)

All toString method to Lucene90HnswVectorsFormat for testing
and debugging.
This commit is contained in:
Mayya Sharipova 2021-10-15 09:09:27 -04:00 committed by GitHub
parent 7d5df2d6fe
commit c9e56d27a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -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
+ ")";
}
}

View File

@ -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));
}
}