Skip to content

Commit

Permalink
LUCENE-10054: Make sure to use Lucene90 codec in unit tests (#699)
Browse files Browse the repository at this point in the history
Before we were using the default Lucene91 codec, so we weren't exercising the
old format.
  • Loading branch information
jtibshirani committed Feb 23, 2022
1 parent 43e89d6 commit 4364bdd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Expand Up @@ -164,7 +164,7 @@ public final PointsFormat pointsFormat() {
}

@Override
public final KnnVectorsFormat knnVectorsFormat() {
public KnnVectorsFormat knnVectorsFormat() {
return knnVectorsFormat;
}

Expand Down
@@ -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;
}
}
Expand Up @@ -23,12 +23,11 @@
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() {
Expand Down

0 comments on commit 4364bdd

Please sign in to comment.