Fix some minor error reporting issues
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index d95919f..12a6a76 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -1072,7 +1072,7 @@
return this.search(collection, ks);
};
-
+ // To be honest - the collection is already part of the KorapSearch!
public KorapResult search (KorapCollection collection, KorapSearch ks) {
if (DEBUG)
log.trace("Start search");
@@ -1279,7 +1279,7 @@
KorapSearch ks,
MatchCollector mc) {
if (DEBUG)
- log.trace("Start collecting matches");
+ log.trace("Start collecting");
// Init term context
this.termContexts = new HashMap<Term, TermContext>();
@@ -1294,7 +1294,7 @@
// See: http://www.ibm.com/developerworks/java/library/j-benchmark1/index.html
long t1 = System.nanoTime();
- // Only load ID
+ // Only load UID
HashSet<String> fieldsToLoadLocal = new HashSet<>();
fieldsToLoadLocal.add("UID");
@@ -1359,23 +1359,17 @@
}
else {
matchcount++;
- // atomicMatches.add(match);
};
};
- /*
- if (!atomicMatches.isEmpty()) {
- // Add matches to the collector
- mc.add(uniqueDocID, atomicMatches);
- atomicMatches.clear();
- };
- */
+ // Add count to collector
if (matchcount > 0) {
mc.add(uniqueDocID, matchcount);
matchcount = 0;
};
};
+ // Benchmark the collector
mc.setBenchmark(t1, System.nanoTime());
}
catch (IOException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 852710c..7300d24 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -119,6 +119,7 @@
return this.itemsPerPage;
}
+ /*
public String getError() {
return this.error;
@@ -128,6 +129,8 @@
this.error = msg;
}
+ */
+
public String getWarning() {
return this.warning;
}
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 ccca3bd..d1edf4b 100644
--- a/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java
+++ b/src/main/java/de/ids_mannheim/korap/server/KorapResponse.java
@@ -34,7 +34,16 @@
@JsonIgnore
public KorapResponse setError (int code, String msg) {
- return this.setErrstr(msg).setErr(code);
+ this.err = code;
+ this.errstr = msg;
+ return this;
+ };
+
+ @JsonIgnore
+ public KorapResponse setError (String msg) {
+ this.err = 699;
+ this.errstr = msg;
+ return this;
};
public KorapResponse setErrstr (String msg) {
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 94e72e5..eb0119a 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Resource.java
@@ -95,9 +95,8 @@
KorapIndex index = KorapNode.getIndex();
KorapResponse kresp = new KorapResponse(KorapNode.getName(), index.getVersion());
- // kresp.setErr();
if (index == null)
- return kresp.setErrstr("Unable to find index").toJSON();
+ return kresp.setError(601, "Unable to find index").toJSON();
String ID = "Unknown";
int unstaged = 0;
@@ -133,6 +132,9 @@
KorapIndex index = KorapNode.getIndex();
KorapResponse kresp = new KorapResponse(KorapNode.getName(), index.getVersion());
+ if (index == null)
+ return kresp.setError(601, "Unable to find index").toJSON();
+
if (version == null)
version = index.getVersion();
@@ -149,8 +151,10 @@
return kresp.setMsg("Unstaged data was committed").toJSON();
};
+
+
/**
- * Find matches in the lucene index and return them as results.
+ * Find matches in the lucene index based on UIDs and return one match per doc.
*
* @param text_id
*/
@@ -187,17 +191,87 @@
return ks.run(index).toJSON();
};
KorapResult kr = new KorapResult();
- kr.setError("No UUIDs given");
+ kr.setNode(KorapNode.getName());
+ kr.setError(610, "No UUIDs given");
return kr.toJSON();
};
- // Response with error message
- KorapResult kr = new KorapResult();
- kr.setError("Index not found");
- return kr.toJSON();
+
+ return new KorapResponse(
+ KorapNode.getName(),
+ index.getVersion()
+ ).setError(601, "Unable to find index").toJSON();
};
/**
+ * Collect matches and aggregate the UIDs plus matchcount in the database.
+ *
+ * @param text_id
+ */
+ /*
+ @POST
+ @Path("/collect/{resultID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public String find (String json, @Context UriInfo uri) {
+
+ // Get index
+ KorapIndex index = KorapNode.getIndex();
+
+ // No index found
+ if (index == null)
+ return new KorapResponse(
+ KorapNode.getName(),
+ index.getVersion()
+ ).setError(601, "Unable to find index").toJSON();
+
+ // Get the database
+ // Create a database based matchcollector
+
+
+ // TODO: Only search in self documents (REPLICATION FTW!)
+
+ MatchCollector result = index.collect(KorapCollection, KorapSearch, MatchCollector);
+
+
+ // Build Collection based on a list of uids
+ List<String> uids = qp.get("uid");
+ KorapCollection kc = new KorapCollection();
+ kc.filterUIDs(uids.toArray(new String[uids.size()]));
+
+ // TODO: RESTRICT COLLECTION TO ONLY RESPECT SELF DOCS (REPLICATION)
+
+ // Override old collection
+ ks.setCollection(kc);
+
+ // Only return the first match per text
+ ks.setItemsPerResource(1);
+
+ return ks.run(index).toJSON();
+ };
+ KorapResult kr = new KorapResult();
+ kr.setNode(KorapNode.getName());
+ kr.setError(610, "No UUIDs given");
+ return kr.toJSON();
+ };
+
+ return new KorapResponse(
+ KorapNode.getName(),
+ index.getVersion()
+ ).setError(601, "Unable to find index").toJSON();
+ };
+*/
+
+
+
+
+
+ /* These routes are still wip: */
+
+
+
+
+ /**
* Search the lucene index.
*
* @param json JSON-LD string with search and potential meta filters.
@@ -212,13 +286,16 @@
KorapIndex index = KorapNode.getIndex();
// Search index
- if (index != null)
- return new KorapSearch(json).run(index).toJSON();
+ if (index != null) {
+ KorapResult kr = new KorapSearch(json).run(index);
+ kr.setNode(KorapNode.getName());
+ return kr.toJSON();
+ };
- // Response with error message
- KorapResult kr = new KorapResult();
- kr.setError("Index not found");
- return kr.toJSON();
+ return new KorapResponse(
+ KorapNode.getName(),
+ index.getVersion()
+ ).setError(601, "Unable to find index").toJSON();
};
@GET
@@ -279,6 +356,7 @@
// Nothing found
catch (QueryException qe) {
+ // Todo: Make KorapMatch rely on KorapResponse!
KorapMatch km = new KorapMatch();
km.setError(qe.getMessage());
return km.toJSON();
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
index e4dccc4..1623e92 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -168,7 +168,7 @@
KorapResult kr = new KorapSearch("{ query").run(ki);
assertEquals(0, kr.getTotalResults());
- assertNotNull(kr.getError());
+ assertNotNull(kr.getErr());
};
@@ -529,7 +529,7 @@
String json = getString(getClass().getResource("/queries/bsp-bug.jsonld").getFile());
KorapResult kr = new KorapSearch(json).run(ki);
- assertEquals(kr.getError(), "Operation needs exactly two operands");
+ assertEquals(kr.getErrstr(), "Operation needs exactly two operands");
};