Minor changes before the blackout
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index c2e6720..be261b6 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -99,6 +99,9 @@
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.
@@ -133,6 +136,9 @@
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();
@@ -379,23 +385,36 @@
};
// Commit changes to the index
- public void commit () throws IOException {
-
- // No writer opened
- if (this.writer == null)
- return;
+ public void commit (boolean force) throws IOException {
// There is something to commit
- if (commitCounter > 0) {
- this.writer.commit();
- commitCounter = 0;
- this.closeReader();
+ if (commitCounter > 0 || !force) {
+ this.commit();
};
};
+ 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();
+ };
+
// Return the number of unstaged texts
- public int getUnstaged () {
- return this.commitCounter;
+ public boolean getUnstaged () throws IOException {
+ if (commitCounter > 0)
+ return true;
+
+ // Open writer if not already opened
+ if (this.writer == null)
+ this.writer = new IndexWriter(this.directory, this.config);
+
+ return this.writer.hasUncommittedChanges();
};
// Get autoCommit valiue
diff --git a/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java b/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java
index dbcbdd7..5ce6869 100644
--- a/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java
+++ b/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java
@@ -10,10 +10,6 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
-/*
- Todo: Ignore unstaged information as this may be incorrect in
- Multithreading environment.
-*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -21,7 +17,8 @@
ObjectMapper mapper = new ObjectMapper();
private String errstr, msg, version, node, listener;
- private int err, unstaged;
+ private int err;
+ private boolean unstaged;
private int totalResults;
private long totalTexts;
private String benchmark;
@@ -92,11 +89,11 @@
return this;
};
- public int getUnstaged () {
+ public boolean getUnstaged () {
return this.unstaged;
};
- public KorapResponse setUnstaged (int unstaged) {
+ public KorapResponse setUnstaged (boolean unstaged) {
this.unstaged = unstaged;
return this;
};
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 aa718ce..c92ee1d 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Resource.java
@@ -104,6 +104,7 @@
*/
/*
* Support GZip:
+ * oR MAYBE IT'S ALREADY SUPPORTED ....
* http://stackoverflow.com/questions/19765582/how-to-make-jersey-use-gzip-compression-for-the-response-message-body
*/
@PUT
@@ -128,7 +129,7 @@
return kresp.setError(601, "Unable to find index").toJSON();
String ID = "Unknown";
- int unstaged = 0;
+ boolean unstaged = false;
try {
FieldDocument fd = index.addDoc(uid, json);
ID = fd.getID();
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
index b2a0507..ef3a3f8 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
@@ -78,4 +78,29 @@
// KorapQuery kq = new KorapQuery("text");
// ki.search();
};
+
+ @Test
+ public void indexAlteration () throws IOException {
+ KorapIndex ki = new KorapIndex();
+
+ assertEquals(0, ki.numberOf("base", "documents"));
+
+ FieldDocument fd = new FieldDocument();
+ fd.addString("name", "Peter");
+ ki.addDoc(fd);
+
+ assertEquals(0, ki.numberOf("base", "documents"));
+
+ fd = new FieldDocument();
+ fd.addString("name", "Michael");
+ ki.addDoc(fd);
+
+ assertEquals(0, ki.numberOf("base", "documents"));
+
+ ki.commit();
+
+ assertEquals(2, ki.numberOf("base", "documents"));
+
+ // hasDeletions, hasPendingMerges
+ };
};
diff --git a/src/test/java/de/ids_mannheim/korap/server/TestResource.java b/src/test/java/de/ids_mannheim/korap/server/TestResource.java
index 08ae610..a5a81f9 100644
--- a/src/test/java/de/ids_mannheim/korap/server/TestResource.java
+++ b/src/test/java/de/ids_mannheim/korap/server/TestResource.java
@@ -64,7 +64,6 @@
@Test
public void testResource() throws IOException {
- int unstaged = 1;
for (String i : new String[] {"00001",
"00002",
"00003",
@@ -81,7 +80,7 @@
assertEquals(kresp.getNode(), "milena");
assertEquals(kresp.getErr(), 0);
- assertEquals(kresp.getUnstaged(), unstaged++);
+ assertEquals(kresp.getUnstaged(), true);
};
KorapResponse kresp = target.path("/index").