properties now have krill-prefixes, added some docs to KrillIndex
diff --git a/Changes b/Changes
index 41f3c39..ede43f5 100644
--- a/Changes
+++ b/Changes
@@ -17,7 +17,8 @@
moved KorapResult to response/Result,
renamed KorapResponse to Response,
moved model/* to index,
- moved meta/SearchContext to response/SearchContext (diewald)
+ moved meta/SearchContext to response/SearchContext,
+ krillified property files (diewald)
- [documentation] Improved documentation for API classes (diewald)
0.50 2015-02-23
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index 57ac31c..6fb9fb1 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -24,19 +24,19 @@
* and proprietary meta objects.
*
* <blockquote><pre>
- * // Create a new krill search object passing a KoralQuery string
+ * // Create a new krill search object by passing a KoralQuery string
* Krill krill = new Krill(koralQueryString);
*
- * // Run the query on an index - receive a search result
- * KrillResult kr = krill.apply(new KrillIndex());
+ * // Apply the query to an index and receive a search result
+ * Result result = krill.apply(new KrillIndex());
* </pre></blockquote>
*
* @author diewald
* @author margaretha
*
- * @see KrillMeta
* @see KrillCollection
* @see KrillQuery
+ * @see KrillMeta
* @see KrillIndex
*/
/*
@@ -50,7 +50,6 @@
// Logger
private final static Logger log = LoggerFactory.getLogger(Krill.class);
-
/**
* Construct a new Krill object.
@@ -90,6 +89,8 @@
try {
this.spanQuery = query.toQuery();
}
+
+ // Add the error to the KoralQuery response
catch (QueryException q) {
this.addError(q.getErrorCode(), q.getMessage());
};
@@ -204,7 +205,7 @@
this.addError(q.getErrorCode(), q.getMessage());
};
- // No errors occured - parse meta object
+ // Parse meta object
if (!this.hasErrors() && json.has("meta"))
this.setMeta(new KrillMeta(json.get("meta")));
@@ -226,6 +227,7 @@
* Set the associated {@link KrillIndex} object.
*
* @param index The associated {@link KrillIndex} object.
+ * @return The {@link Krill} object for chaining.
*/
public Krill setIndex (KrillIndex index) {
this.index = index;
@@ -280,18 +282,32 @@
};
- @Deprecated
- public JsonNode getRequest () {
- return this.request;
- };
-
-
+ /**
+ * Get the associated {@link SpanQuery} deserialization
+ * (i.e. the internal correspandence to KoralQuery's query object).
+ *
+ * <strong>Warning</strong>: SpanQueries may be lazy deserialized
+ * in future versions of Krill, rendering this API obsolete.
+ *
+ * @return The deserialized {@link SpanQuery} object.
+ */
@Deprecated
public SpanQuery getSpanQuery () {
return this.spanQuery;
};
+ /**
+ * Set the SpanQuery by means of a {@link SpanQueryWrapper} object
+ * (i.e. the internal correspandence to KoralQuery's query object).
+ *
+ * <strong>Warning</strong>: SpanQueries may be lazy deserialized
+ * in future versions of Krill, rendering this API obsolete.
+ *
+ * @param query The {@link SpanQueryWrapper} to unwrap
+ * the {@link SpanQuery} object.
+ * @return The {@link Krill} object for chaining.
+ */
@Deprecated
public Krill setSpanQuery (SpanQueryWrapper sqwi) {
try {
@@ -303,10 +319,27 @@
return this;
};
-
+
+ /**
+ * Set the {@link SpanQuery} object
+ * (i.e. the internal correspandence to KoralQuery's query object).
+ *
+ * <strong>Warning</strong>: SpanQueries may be lazy deserialized
+ * in future versions of Krill, rendering this API obsolete.
+ *
+ * @param query The {@link SpanQuery} object.
+ * @return The {@link Krill} object for chaining.
+ */
@Deprecated
public Krill setSpanQuery (SpanQuery sq) {
this.spanQuery = sq;
return this;
};
+
+
+ // Requests are out - queries will be mirrored completely
+ @Deprecated
+ public JsonNode getRequest () {
+ return this.request;
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 70e99bb..0672362 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -40,39 +40,42 @@
/**
* KrillIndex implements a simple API for searching in and writing to a
* Lucene index and requesting several information about the index' nature.
+ * Please consult {@link Krill} for the preferred use of this class.
* <br />
*
* <blockquote><pre>
* KrillIndex ki = new KrillIndex(
* new MMapDirectory(new File("/myindex"))
* );
+ * Result result = new Krill(koralQueryString).apply(ki);
* </pre></blockquote>
*
- * Properties can be stored in a properies file called 'index.properties'.
- * Relevant properties are <code>lucene.version</code> and
- * <code>lucene.name</code>.
+ * Properties can be stored in a properies file called <tt>krill.properties</tt>.
+ * Relevant properties are <tt>krill.version</tt> and
+ * <tt>krill.name</tt>.
*
* @author diewald
*/
/*
+ NOTE: Search could run in parallel on atomic readers (although Lucene developers
+ strongly discourage that). Benefits are not clear and testing is harder,
+ so let's stick to serial processing for now.
TODO: Add word count as a meta data field!
- TODO: Validate document import!
- TODO: DON'T STORE THE TEXT IN THE TOKENS FIELD!
- It has only to be lifted for match views!!!
- TODO: Support layer for specific foundries (IMPORTANT)
+ TODO: Improve validation of document import!
+ TODO: Don't store the text in the token field!
+ (It has only to be lifted for match views!
+ Benchmark how worse that is!)
+ TODO: Support layer for specific foundries in terminfo (IMPORTANT)
TODO: Use FieldCache!
TODO: Reuse the indexreader everywhere - it should be threadsafe!
+ TODO: Support document removal!
+ TODO: Support document update!
+ TODO: Support callback for interrupts (to stop the searching)!
+ TODO: Support multiple indices (Probably).
http://invertedindex.blogspot.co.il/2009/04/lucene-dociduid-mapping-and-payload.html
see korap/search.java -> retrieveTokens
- Todo: Support document removal!
- Todo: Support document update! // it's now part of IndexWriter
-
- Support a callback for interrupts (to stop the searching)!
-
- Support multiple indices.
-
Support frequency search with regular expressions, so multiple bookkeeping:
c<:VVFIN:ging:gehen:past::
c>:VVFIN:gnig:neheg:past::
@@ -80,33 +83,6 @@
-> c:VVFIN:[^:]*?:gehen:past:...
*/
public class KrillIndex {
- // Todo: Use configuration
- private int maxTermRelations = 100, // Last line of defense
- autoCommit = 500;
-
- private Directory directory;
-
- // Temp:
- public IndexReader reader;
-
- private IndexWriter writer;
- private IndexWriterConfig config;
- private IndexSearcher searcher;
- private boolean readerOpen = false;
-
- // The commit counter is only there for
- // counting unstaged changes per thread (for bulk insertions)
- // It does not represent real unstaged documents.
- private int commitCounter = 0;
- private HashMap termContexts;
- private ObjectMapper mapper = new ObjectMapper();
- private String version, name;
-
- private byte[] pl = new byte[4];
- private static ByteBuffer
- bb = ByteBuffer.allocate(4),
- bbOffset = ByteBuffer.allocate(8),
- bbTerm = ByteBuffer.allocate(16);
// Logger
private final static Logger log = LoggerFactory.getLogger(KrillIndex.class);
@@ -114,9 +90,40 @@
// This advices the java compiler to ignore all loggings
public static final boolean DEBUG = false;
+ // TODO: Use configuration instead.
+ // Last line of defense against DOS
+ private int maxTermRelations = 100;
+ private int autoCommit = 500;
+ private String version;
+ private String name;
+
+ // Temp:
+ private IndexReader reader;
+
+ private IndexWriter writer;
+ private IndexWriterConfig config;
+ private IndexSearcher searcher;
+ private boolean readerOpen = false;
+ private Directory directory;
+
+ // The commit counter is only there for
+ // counting unstaged changes per thread (for bulk insertions)
+ // It does not represent real unstaged documents.
+ private int commitCounter = 0;
+ private HashMap termContexts;
+ private ObjectMapper mapper = new ObjectMapper();
+
+ private byte[] pl = new byte[4];
+ private static ByteBuffer
+ bb = ByteBuffer.allocate(4),
+ bbOffset = ByteBuffer.allocate(8),
+ bbTerm = ByteBuffer.allocate(16);
+
+ // Some initializations ...
+ // TODO: This should probably happen at a more central point
{
Properties prop = new Properties();
- URL file = getClass().getClassLoader().getResource("index.properties");
+ URL file = getClass().getClassLoader().getResource("krill.properties");
// File found
if (file != null) {
@@ -125,8 +132,30 @@
try {
InputStream fr = new FileInputStream(f);
prop.load(fr);
- this.version = prop.getProperty("lucene.version");
- this.name = prop.getProperty("lucene.name");
+ this.version = prop.getProperty("krill.version");
+ this.name = prop.getProperty("krill.name");
+
+ // Check for auto commit value
+ String stringProp = prop.getProperty("krill.index.commit.auto");
+ if (stringProp != null) {
+ try {
+ this.autoCommit = Integer.parseInt(stringProp);
+ }
+ catch (NumberFormatException e) {
+ log.error("krill.index.commit.auto expected to be a numerical value");
+ };
+ };
+
+ // Check for maximum term relations
+ stringProp = prop.getProperty("krill.index.relations.max");
+ if (stringProp != null) {
+ try {
+ this.maxTermRelations = Integer.parseInt(stringProp);
+ }
+ catch (NumberFormatException e) {
+ log.error("krill.index.commit.auto expected to be a numerical value");
+ };
+ };
}
// Unable to read property file
@@ -138,7 +167,8 @@
/**
- * Constructs a new KrillIndex in-memory.
+ * Constructs a new KrillIndex.
+ * This will be in-memory.
*
* @throws IOException
*/
@@ -150,25 +180,14 @@
/**
* Constructs a new KrillIndex bound to a persistant index.
*
- * @param index Path to an {@link FSDirectory} index
- * @throws IOException
- */
- public KrillIndex (String index) throws IOException {
- this(FSDirectory.open(new File( index )));
- };
-
-
- /**
- * Constructs a new KrillIndex bound to a persistant index.
- *
* @param directory A {@link Directory} pointing to an index
* @throws IOException
*/
public KrillIndex (Directory directory) throws IOException {
this.directory = directory;
- // TODO: Shouldn't be here
// Add analyzers
+ // TODO: Should probably not be here
Map<String,Analyzer> analyzerPerField = new HashMap<String,Analyzer>();
analyzerPerField.put("textClass", new WhitespaceAnalyzer(Version.LUCENE_CURRENT));
analyzerPerField.put("foundries", new WhitespaceAnalyzer(Version.LUCENE_CURRENT));
@@ -203,45 +222,53 @@
/**
- * Close the connections of the index reader and the writer.
- * @throws IOException
- */
- public void close () throws IOException {
- this.closeReader();
- this.closeWriter();
- };
-
-
- // Get index reader object
+ * The Lucene {@link IndexReader} object.
+ *
+ * Will be opened, in case it's closed.
+ *
+ * @return The {@link IndexReader} object.
+ */
public IndexReader reader () {
- if (!readerOpen)
- this.openReader();
// Todo: Maybe use DirectoryReader.openIfChanged(DirectoryReader)
-
+ if (!readerOpen)
+ this.openReader();
return this.reader;
};
-
- // Get index searcher object
+
+ /**
+ * The Lucene {@link IndexWriter} object.
+ *
+ * Will be created, in case it doesn't exist yet.
+ *
+ * @return The {@link IndexWriter} object.
+ * @throws IOException
+ */
+ public IndexWriter writer () throws IOException {
+ // Open writer if not already opened
+ if (this.writer == null)
+ this.writer = new IndexWriter(this.directory, this.config);
+ return this.writer;
+ };
+
+
+ /**
+ * The Lucene {@link IndexSearcher} object.
+ *
+ * Will be created, in case it doesn't exist yet.
+ *
+ * @return The {@link IndexSearcher} object.
+ */
public IndexSearcher searcher () {
- if (this.searcher == null) {
+ if (this.searcher == null)
this.searcher = new IndexSearcher(this.reader());
- };
return this.searcher;
};
- // Close index writer
- public void closeWriter () throws IOException {
- if (this.writer != null)
- this.writer.close();
- };
-
-
// Open index reader
- public void openReader () {
+ private void openReader () {
try {
-
// open reader
this.reader = DirectoryReader.open(this.directory);
readerOpen = true;
@@ -251,34 +278,100 @@
// Failed to open reader
catch (IOException e) {
- //e.printStackTrace();
+ // e.printStackTrace();
log.warn( e.getLocalizedMessage() );
};
};
// Close index reader
- public void closeReader () throws IOException {
+ private void closeReader () throws IOException {
if (readerOpen) {
this.reader.close();
readerOpen = false;
};
};
- /*
- * Some of these addDoc methods will probably be DEPRECATED,
- * as they were added while the API changed slowly.
- */
- // Add document to index as FieldDocument
- public FieldDocument addDoc (FieldDocument fd) {
+ // Close index writer
+ private void closeWriter () throws IOException {
+ if (this.writer != null)
+ this.writer.close();
+ };
+
+
+ /**
+ * Close the associated {@link IndexReader}
+ * and the associated {@link IndexWriter},
+ * in case they are opened.
+ *
+ * @throws IOException
+ */
+ public void close () throws IOException {
+ this.closeReader();
+ this.closeWriter();
+ };
+
+
+ /**
+ * Commit staged data to the index,
+ * if the commit counter indicates there is staged data.
+ *
+ * @param force Force the commit,
+ * even if there is no staged data.
+ * @throws IOException
+ */
+ public void commit (boolean force) throws IOException {
+ // There is something to commit
+ if (commitCounter > 0 || !force)
+ this.commit();
+ };
+
+
+ /**
+ * Commit staged data to the index.
+ *
+ * @throws IOException
+ */
+ public void commit () throws IOException {
+ this.writer().commit();
+ commitCounter = 0;
+ this.closeReader();
+ };
+
+
+ /**
+ * Get autocommit value.
+ *
+ * @return The autocommit value.
+ */
+ public int getAutoCommit () {
+ return this.autoCommit;
+ };
+
+
+ /**
+ * Set the autocommit value.
+ *
+ * @param value The autocommit value.
+ */
+ public void setAutoCommit (int value) {
+ this.autoCommit = value;
+ };
+
+
+ /**
+ * Add a document to the index as a {@link FieldDocument}.
+ *
+ * @param doc The {@link FieldDocument} to add to the index.
+ * @return The {@link FieldDocument}, which means, the same
+ * object, that was passed to the method.
+ */
+ public FieldDocument addDoc (FieldDocument doc) {
try {
- // Open writer if not already opened
- if (this.writer == null)
- this.writer = new IndexWriter(this.directory, this.config);
// Add document to writer
- this.writer.addDocument( fd.doc );
+ this.writer().addDocument( doc.doc );
if (++commitCounter > autoCommit) {
this.commit();
commitCounter = 0;
@@ -287,37 +380,29 @@
// Failed to add document
catch (IOException e) {
- log.error("File json not found");
+ log.error("Unable to add document");
};
- return fd;
- };
- // Add document to index as JSON object with a unique ID
- public FieldDocument addDoc (int uid, String json) throws IOException {
- FieldDocument fd = this.mapper.readValue(json, FieldDocument.class);
- fd.setUID(uid);
- return this.addDoc(fd);
+ return doc;
};
- // Add document to index as JSON object
+ /**
+ * Add a document to the index as a JSON string.
+ *
+ * @param json The document to add to the index as a string.
+ * @return The created {@link FieldDocument}.
+ * @throws IOException
+ */
public FieldDocument addDoc (String json) throws IOException {
FieldDocument fd = this.mapper.readValue(json, FieldDocument.class);
return this.addDoc(fd);
};
- // Add document to index as JSON file
- public FieldDocument addDoc (File json) {
- try {
- FieldDocument fd = this.mapper.readValue(json, FieldDocument.class);
- return this.addDoc(fd);
- }
- catch (IOException e) {
- log.error("File json not parseable");
- };
- return (FieldDocument) null;
- };
+
+ // To document:
+
// Add document to index as JSON file
@@ -326,7 +411,7 @@
};
- private FieldDocument _addDocfromFile (String json, boolean gzip) {
+ public FieldDocument addDocfromFile (String json, boolean gzip) {
try {
if (gzip) {
@@ -350,13 +435,26 @@
// Add document to index as JSON file (possibly gzipped)
public FieldDocument addDocFile(String json, boolean gzip) {
- return this.addDoc(this._addDocfromFile(json, gzip));
+ return this.addDoc(this.addDocfromFile(json, gzip));
};
+ /**
+ * Add a document to the index as a JSON string
+ * with a unique integer ID (unique throughout the index
+ * or even throughout the cluster of indices).
+ *
+ * @param uid The unique document identifier.
+ * @param json The document to add to the index as a string.
+ * @return The created {@link FieldDocument}.
+ * @throws IOException
+ */
+
+
+
// Add document to index as JSON file (possibly gzipped)
public FieldDocument addDocFile(int uid, String json, boolean gzip) {
- FieldDocument fd = this._addDocfromFile(json, gzip);
+ FieldDocument fd = this.addDocfromFile(json, gzip);
if (fd != null) {
fd.setUID(uid);
return this.addDoc(fd);
@@ -365,38 +463,6 @@
};
- // Commit changes to the index
- public void commit (boolean force) throws IOException {
- // There is something to commit
- if (commitCounter > 0 || !force)
- this.commit();
- };
-
-
- // Commit changes to the index
- public void commit () throws IOException {
- // Open writer if not already opened
- if (this.writer == null)
- this.writer = new IndexWriter(this.directory, this.config);
-
- // Force commit
- this.writer.commit();
- commitCounter = 0;
- this.closeReader();
- };
-
-
- // Get autoCommit valiue
- public int autoCommit () {
- return this.autoCommit;
- };
-
-
- // Set autoCommit value
- public void autoCommit (int number) {
- this.autoCommit = number;
- };
-
// Search for meta information in term vectors
private long numberOfAtomic (Bits docvec,
diff --git a/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java b/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
index 82acd68..f0e9ddc 100644
--- a/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
+++ b/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
@@ -247,6 +247,7 @@
* Set the unique identifier of the document.
*
* @param UID The unique identifier of the document as an integer.
+ * @return The invocant for chaining.
*/
public void setUID (int UID) {
this.UID = UID;
@@ -258,6 +259,7 @@
*
* @param UID The unique identifier of the document as a
* string representing an integer.
+ * @return The invocant for chaining.
* @throws NumberFormatException
*/
public void setUID (String UID) throws NumberFormatException {
diff --git a/src/main/java/de/ids_mannheim/korap/index/Indexer.java b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
index 7526767..7c7acfd 100644
--- a/src/main/java/de/ids_mannheim/korap/index/Indexer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
@@ -31,16 +31,16 @@
*
* @param prop A {@link Properties} object with
* at least the following information:
- * <tt>lucene.indexDir</tt>.
+ * <tt>krill.indexDir</tt>.
* @throws IOException
*/
public Indexer (Properties prop) throws IOException {
- this.indexDir = prop.getProperty("lucene.indexDir");
+ this.indexDir = prop.getProperty("krill.indexDir");
System.out.println("Index to " + this.indexDir);
// Default to 1000 documents till the next commit
- String commitCount = prop.getProperty("lucene.index.commit.count", "1000");
+ String commitCount = prop.getProperty("krill.index.commit.count", "1000");
// Create a new index object based on the directory
this.index = new KrillIndex(new MMapDirectory(new File(indexDir)));
diff --git a/src/main/java/de/ids_mannheim/korap/server/Node.java b/src/main/java/de/ids_mannheim/korap/server/Node.java
index 4bf00ea..6aebd2d 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Node.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Node.java
@@ -61,22 +61,22 @@
try {
InputStream file = new FileInputStream(
Node.class.getClassLoader()
- .getResource("server.properties")
+ .getResource("krill.properties")
.getFile()
);
Properties prop = new Properties();
prop.load(file);
// Node properties
- path = prop.getProperty("lucene.indexDir", path);
- name = prop.getProperty("lucene.server.name", name);
- BASE_URI = prop.getProperty("lucene.server.baseURI", BASE_URI);
+ path = prop.getProperty("krill.indexDir", path);
+ name = prop.getProperty("krill.server.name", name);
+ BASE_URI = prop.getProperty("krill.server.baseURI", BASE_URI);
// Database properties
- dbUser = prop.getProperty("lucene.db.user", dbUser);
- dbPwd = prop.getProperty("lucene.db.pwd", dbPwd);
- dbClass = prop.getProperty("lucene.db.class", dbClass);
- dbURL = prop.getProperty("lucene.db.jdbcURL", dbURL);
+ dbUser = prop.getProperty("krill.db.user", dbUser);
+ dbPwd = prop.getProperty("krill.db.pwd", dbPwd);
+ dbClass = prop.getProperty("krill.db.class", dbClass);
+ dbURL = prop.getProperty("krill.db.jdbcURL", dbURL);
}
catch (IOException e) {
@@ -125,7 +125,7 @@
new Runnable() {
@Override
public void run() {
- log.info("Stup Server");
+ log.info("Stop Server");
// staaahp!
server.stop();
}
diff --git a/src/main/java/de/ids_mannheim/korap/server/Resource.java b/src/main/java/de/ids_mannheim/korap/server/Resource.java
index d48884d..39e5437 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Resource.java
@@ -150,7 +150,8 @@
String ID = "Unknown";
try {
- FieldDocument fd = index.addDoc(uid, json);
+ FieldDocument fd = index.addDoc(json);
+ fd.setUID(uid);
ID = fd.getID();
}
// Set HTTP to ???
diff --git a/src/main/resources/krill.properties.info b/src/main/resources/krill.properties.info
new file mode 100644
index 0000000..b9fcc72
--- /dev/null
+++ b/src/main/resources/krill.properties.info
@@ -0,0 +1,19 @@
+krill.version = ${project.version}
+krill.name = ${project.name}
+
+# Krill Backend properties
+krill.properties = true
+krill.indexDir = [PATH TO INDEX DIRECTORY]
+krill.server.name = [UNIQUE NODE NAME]
+krill.server.baseURI = [LISTEN-URL INCLUDING PORT]
+
+# Krill Database properties
+krill.db.class = org.mariadb.jdbc.Driver
+krill.db.URL = jdbc:mysql://[DB_IP]:[DB_PORT]/[DB_NAME]
+krill.db.pwd = [DB_PWD]
+krill.db.user = [DB_USER]
+
+krill.index.commit.count = 134217000
+krill.index.commit.log = log/krill.commit.log
+krill.index.commit.auto = 500
+krill.index.relations.max = 100
diff --git a/src/main/resources/server.properties.info b/src/main/resources/server.properties.info
deleted file mode 100644
index f35a016..0000000
--- a/src/main/resources/server.properties.info
+++ /dev/null
@@ -1,17 +0,0 @@
-lucene.version = ${project.version}
-lucene.name = ${project.name}
-
-# Lucene Backend properties
-lucene.properties = true
-lucene.indexDir = [PATH TO INDEX DIRECTORY]
-lucene.node.name = [UNIQUE NODE NAME]
-lucene.node.baseURI = [LISTEN-URL INCLUDING PORT]
-
-# Lucene Database properties
-lucene.db.class = org.mariadb.jdbc.Driver
-lucene.db.URL = jdbc:mysql://[DB_IP]:[DB_PORT]/[DB_NAME]
-lucene.db.pwd = [DB_PWD]
-lucene.db.user = [DB_USER]
-
-lucene.index.commit.count = 134217000
-lucene.index.commit.log = log/korap.commit.log
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
index 18ec228..d9baef3 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
@@ -37,51 +37,49 @@
@Test
public void indexExample1 () throws IOException {
- KrillIndex ki = new KrillIndex();
+ KrillIndex ki = new KrillIndex();
- FieldDocument fd = new FieldDocument();
- fd.addTV("base",
- "a b c",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
- "[(2-3)s:b|i:b|_1#2-3]" +
- "[(4-5)s:c|i:c|_2#4-5]");
- ki.addDoc(fd);
+ FieldDocument fd = new FieldDocument();
+ fd.addTV("base",
+ "a b c",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(2-3)s:b|i:b|_1#2-3]" +
+ "[(4-5)s:c|i:c|_2#4-5]");
+ ki.addDoc(fd);
- fd = new FieldDocument();
- fd.addTV("base",
- "x y z",
- "[(0-1)s:x|i:x|_0#0-2|-:t$<i>3]" +
- "[(3-4)s:y|i:y|_1#3-4]" +
- "[(6-7)s:z|i:z|_2#6-7]"); // 3
- ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addTV("base",
+ "x y z",
+ "[(0-1)s:x|i:x|_0#0-2|-:t$<i>3]" +
+ "[(3-4)s:y|i:y|_1#3-4]" +
+ "[(6-7)s:z|i:z|_2#6-7]"); // 3
+ ki.addDoc(fd);
+ ki.commit();
+
+ String field = "base";
+ for (AtomicReaderContext atomic : ki.reader().leaves()) {
+ PositionsToOffset pto = new PositionsToOffset(atomic, field);
- ki.commit();
+ pto.add(0,1);
+ pto.add(0,2);
+ pto.add(1,2);
+ pto.add(1,1);
+ pto.add(1,20);
- String field = "base";
+ assertEquals("Start 0,1", pto.start(0,1), 2);
+ assertEquals("End 0,1", pto.end(0,1), 3);
- for (AtomicReaderContext atomic : ki.reader().leaves()) {
- PositionsToOffset pto = new PositionsToOffset(atomic, field);
+ assertEquals("Start 0,2", pto.start(0,2), 4);
+ assertEquals("End 0,2", pto.end(0,2), 5);
- pto.add(0,1);
- pto.add(0,2);
- pto.add(1,2);
- pto.add(1,1);
- pto.add(1,20);
+ assertEquals("Start 1,2", pto.start(1,2), 6);
+ assertEquals("End 1,2", pto.end(1,2), 7);
- assertEquals("Start 0,1", pto.start(0,1), 2);
- assertEquals("End 0,1", pto.end(0,1), 3);
-
- assertEquals("Start 0,2", pto.start(0,2), 4);
- assertEquals("End 0,2", pto.end(0,2), 5);
-
- assertEquals("Start 1,2", pto.start(1,2), 6);
- assertEquals("End 1,2", pto.end(1,2), 7);
-
- assertEquals("Start 1,1", pto.start(1,1), 3);
- assertEquals("End 1,1", pto.end(1,1), 4);
-
- assertEquals("Start 1,20", pto.start(1,20), 0);
- assertEquals("End 1,20", pto.end(1,20), -1);
- };
+ assertEquals("Start 1,1", pto.start(1,1), 3);
+ assertEquals("End 1,1", pto.end(1,1), 4);
+
+ assertEquals("Start 1,20", pto.start(1,20), 0);
+ assertEquals("End 1,20", pto.end(1,20), -1);
+ };
};
};
diff --git a/src/test/resources/index.properties b/src/test/resources/index.properties
deleted file mode 100644
index b8b6980..0000000
--- a/src/test/resources/index.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-lucene.version = ${project.version}
-lucene.name = ${project.name}