You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ju...@apache.org on 2022/07/02 21:02:49 UTC
[lucene] branch branch_9x updated: LUCENE-10577: Add vectors format unit test and fix toString (#998)
This is an automated email from the ASF dual-hosted git repository.
julietibs pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 359b495129c LUCENE-10577: Add vectors format unit test and fix toString (#998)
359b495129c is described below
commit 359b495129c68403e7aa36b0a1455e75a3a033e1
Author: Julie Tibshirani <ju...@apache.org>
AuthorDate: Sat Jul 2 19:00:29 2022 +0200
LUCENE-10577: Add vectors format unit test and fix toString (#998)
We forgot to add this unit test when introducing the new 9.3 vectors format.
This commit adds the test and fixes issues it uncovered in toString.
---
.../codecs/lucene93/Lucene93HnswVectorsFormat.java | 4 +--
.../lucene93/TestLucene93HnswVectorsFormat.java | 42 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene93/Lucene93HnswVectorsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene93/Lucene93HnswVectorsFormat.java
index e795920d254..0dad7f06a00 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene93/Lucene93HnswVectorsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene93/Lucene93HnswVectorsFormat.java
@@ -141,7 +141,7 @@ public final class Lucene93HnswVectorsFormat extends KnnVectorsFormat {
* @param beamWidth the size of the queue maintained during graph construction.
*/
public Lucene93HnswVectorsFormat(int maxConn, int beamWidth) {
- super("lucene93HnswVectorsFormat");
+ super("Lucene93HnswVectorsFormat");
this.maxConn = maxConn;
this.beamWidth = beamWidth;
}
@@ -158,7 +158,7 @@ public final class Lucene93HnswVectorsFormat extends KnnVectorsFormat {
@Override
public String toString() {
- return "lucene93HnswVectorsFormat(name = lucene93HnswVectorsFormat, maxConn = "
+ return "Lucene93HnswVectorsFormat(name=Lucene93HnswVectorsFormat, maxConn="
+ maxConn
+ ", beamWidth="
+ beamWidth
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene93/TestLucene93HnswVectorsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene93/TestLucene93HnswVectorsFormat.java
new file mode 100644
index 00000000000..76659602bf8
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene93/TestLucene93HnswVectorsFormat.java
@@ -0,0 +1,42 @@
+/*
+ * 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.codecs.lucene93;
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.codecs.KnnVectorsFormat;
+import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
+import org.apache.lucene.tests.util.TestUtil;
+
+public class TestLucene93HnswVectorsFormat extends BaseKnnVectorsFormatTestCase {
+ @Override
+ protected Codec getCodec() {
+ return TestUtil.getDefaultCodec();
+ }
+
+ public void testToString() {
+ Lucene93Codec customCodec =
+ new Lucene93Codec() {
+ @Override
+ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
+ return new Lucene93HnswVectorsFormat(10, 20);
+ }
+ };
+ String expectedString =
+ "Lucene93HnswVectorsFormat(name=Lucene93HnswVectorsFormat, maxConn=10, beamWidth=20)";
+ assertEquals(expectedString, customCodec.getKnnVectorsFormatForField("bogus_field").toString());
+ }
+}