Skip to content

Commit

Permalink
HSEARCH-4948 Register codec
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Nov 10, 2023
1 parent 4bae254 commit ea2e0ce
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.lucene95.Lucene95Codec;
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;

public class HibernateSearchLuceneCodec extends FilterCodec {

private static final Codec DEFAULT_CODEC = new Lucene95Codec();

private final KnnVectorsFormat knnVectorsFormat;

public HibernateSearchLuceneCodec(LuceneIndexModel model) {
super( HibernateSearchLuceneCodec.class.getSimpleName(), Codec.getDefault() );
this.knnVectorsFormat = new IndexModelBasedPerFieldKnnVectorsFormat( model );
this( new IndexModelBasedPerFieldKnnVectorsFormat( model ) );
}

public HibernateSearchLuceneCodec(KnnVectorsFormat knnVectorsFormat) {
super( HibernateSearchLuceneCodec.class.getSimpleName(), DEFAULT_CODEC );
this.knnVectorsFormat = knnVectorsFormat;
}

public HibernateSearchLuceneCodec() {
this( (KnnVectorsFormat) null );
// NOTE: we are not providing access to a PerFieldKnnVectorsFormat based on a model,
// since max connections and beam width parameters configured by vector format are only used by an index writer;
// and we also are crating and passing the codec to the writer ourselves.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.hibernate.search.backend.lucene.lowlevel.codec.impl.HibernateSearchLuceneCodec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.backend.lucene.lowlevel.codec.impl;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene95.Lucene95Codec;

class HibernateSearchLuceneCodecTest {
@Test
void checkDefaultCodec() {
assertThat( Codec.getDefault() )
.isNotNull()
.extracting( Object::getClass )
.isEqualTo( Lucene95Codec.class );
}
}

0 comments on commit ea2e0ce

Please sign in to comment.