Support loading mmapable indices by path
Change-Id: Iaaeb8dc987c3da4b3f72e84535dce975a22444cf
diff --git a/Changes b/Changes
index 63b8941..3cd095a 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+0.62.2 2024-02-19
+ - [feature] Support MMap directory parameters directly
+ for KrillIndex (without the need for Lucene dependencies)
+ (diewald)
+
0.62.1 2024-01-25
- [security] Introduction of dependabot alerts (margaretha)
- [security] Update dependencies (diewald)
diff --git a/pom.xml b/pom.xml
index 955ee4c..a304cfb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
<groupId>de.ids-mannheim.korap.krill</groupId>
<artifactId>Krill</artifactId>
- <version>0.62.1</version>
+ <version>0.62.2</version>
<packaging>jar</packaging>
<name>Krill</name>
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index e19ebd1..2210167 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
+import java.nio.file.Path;
import java.time.LocalDate;
// Java core classes
import java.util.ArrayList;
@@ -44,6 +45,7 @@
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FixedBitSet;
@@ -225,6 +227,19 @@
/**
+ * Constructs a new KrillIndex bound to a persistant index,
+ * that will be lifted as an mmap.
+ *
+ * @param path
+ * A path pointing to an mmapable index
+ * @throws IOException
+ */
+ public KrillIndex (Path path) throws IOException {
+ this.directory = new MMapDirectory(path);
+ };
+
+
+ /**
* Get the version number of the index.
*
* @return A string containing the version number.
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java b/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
index 82fab27..c6b0f3c 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
@@ -93,7 +93,7 @@
public void testIndexRevisionTempFile () throws IOException {
Path tmpdir = Files.createTempDirectory("wiki");
- KrillIndex ki = new KrillIndex(new MMapDirectory(tmpdir));
+ KrillIndex ki = new KrillIndex(tmpdir);
assertEquals("null", ki.getFingerprint());
@@ -204,8 +204,8 @@
@Ignore
public void testIndexRevisionSample () throws IOException {
- KrillIndex ki = new KrillIndex(new MMapDirectory(
- Paths.get(getClass().getResource("/sample-index").getFile())));
+ KrillIndex ki = new KrillIndex(
+ Paths.get(getClass().getResource("/sample-index").getFile()));
assertEquals("Wes8Bd4h1OypPqbWF5njeQ==",ki.getFingerprint());
};