From 4364bdd63ef58b2094dc252018d3c027302af4f4 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Wed, 23 Feb 2022 08:22:59 -0800 Subject: [PATCH] LUCENE-10054: Make sure to use Lucene90 codec in unit tests (#699) Before we were using the default Lucene91 codec, so we weren't exercising the old format. --- .../lucene90/Lucene90Codec.java | 2 +- .../lucene90/Lucene90RWCodec.java | 44 +++++++++++++++++++ .../TestLucene90HnswVectorsFormat.java | 3 +- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/Lucene90RWCodec.java diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene90/Lucene90Codec.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene90/Lucene90Codec.java index 40ba06606bd..f10e35cf9ce 100644 --- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene90/Lucene90Codec.java +++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene90/Lucene90Codec.java @@ -164,7 +164,7 @@ public class Lucene90Codec extends Codec { } @Override - public final KnnVectorsFormat knnVectorsFormat() { + public KnnVectorsFormat knnVectorsFormat() { return knnVectorsFormat; } diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/Lucene90RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/Lucene90RWCodec.java new file mode 100644 index 00000000000..b7c30361d2e --- /dev/null +++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/Lucene90RWCodec.java @@ -0,0 +1,44 @@ +/* + * 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.backward_codecs.lucene90; + +import org.apache.lucene.codecs.KnnVectorsFormat; +import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat; + +public class Lucene90RWCodec extends Lucene90Codec { + + private final KnnVectorsFormat defaultKnnVectorsFormat; + private final KnnVectorsFormat knnVectorsFormat = + new PerFieldKnnVectorsFormat() { + @Override + public KnnVectorsFormat getKnnVectorsFormatForField(String field) { + return defaultKnnVectorsFormat; + } + }; + + public Lucene90RWCodec() { + this.defaultKnnVectorsFormat = + new Lucene90RWHnswVectorsFormat( + Lucene90HnswVectorsFormat.DEFAULT_MAX_CONN, + Lucene90HnswVectorsFormat.DEFAULT_BEAM_WIDTH); + } + + @Override + public KnnVectorsFormat knnVectorsFormat() { + return knnVectorsFormat; + } +} diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java index 8fe6dc24624..49ebbde7595 100644 --- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java +++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java @@ -23,12 +23,11 @@ import static org.apache.lucene.backward_codecs.lucene90.Lucene90HnswVectorsForm 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 TestLucene90HnswVectorsFormat extends BaseKnnVectorsFormatTestCase { @Override protected Codec getCodec() { - return TestUtil.getDefaultCodec(); + return new Lucene90RWCodec(); } public void testToString() {