Permalink
Browse files

Minor fixed to delete docs.

  • Loading branch information...
1 parent 0a2025a commit a8590e887144601d24c81a2cc10f30d7840ba48d Ignacio Perez Gonzalez committed Jan 27, 2012
@@ -136,13 +136,11 @@ public void putDocument(String id, JSONObject fields, JSONObject variables, JSON
BoostingIndexer indexer = engine.getIndexer();
indexer.add(id, new Document(prepareProperties(fields)), Timestamp.inSeconds(), prepareBoosts(variables));
indexer.updateCategories(id, prepareProperties(categories));
- System.out.println(engine.getIndexer().getStats());
}
public void deleteDocument(String id) {
BoostingIndexer indexer = engine.getIndexer();
indexer.del(id);
- System.out.println(engine.getIndexer().getStats());
}
private Map<String, String> prepareProperties(JSONObject jo) {
@@ -50,20 +50,44 @@ public void run() {
print("Invalid or missing argument"); // TODO: descriptive error msg
return;
}
- }
+ } else if(parse instanceof JSONArray) {
+ JSONArray statuses = new JSONArray();
+ JSONArray ja = (JSONArray) parse;
+ if(!validateDocuments(ja)) {
+ res().setStatus(400);
+ print("Invalid or missing argument"); // TODO: descriptive error msg
+ return;
+ }
+ boolean hasError = false;
+ for(Object o: ja) {
+ JSONObject jo = (JSONObject) o;
+ JSONObject status = new JSONObject();
+ try {
+ deleteDocument(api, jo);
+ status.put("added", true);
+ } catch(Exception e) {
+ status.put("added", false);
+ status.put("error", "Invalid or missing argument"); // TODO: descriptive error msg
+ hasError = true;
+ }
+ statuses.add(status);
+ }
+ print(statuses.toJSONString());
+ return;
+ }
} catch (IOException e) {
- if(LOG_ENABLED) LOG.severe("PUT doc, parse input " + e.getMessage());
+ if(LOG_ENABLED) LOG.severe("DELETE doc, parse input " + e.getMessage());
} catch (ParseException e) {
- if(LOG_ENABLED) LOG.severe("PUT doc, parse input " + e.getMessage());
+ if(LOG_ENABLED) LOG.severe("DELETE doc, parse input " + e.getMessage());
} catch (Exception e) {
- if(LOG_ENABLED) LOG.severe("PUT doc " + e.getMessage());
+ if(LOG_ENABLED) LOG.severe("DELETE doc " + e.getMessage());
}
res().setStatus(503);
print("Service unavailable"); // TODO: descriptive error msg
}
private void deleteDocument(IndexEngineApi api, JSONObject jo) {
- String docid = String.valueOf(jo.get("docid")); // TODO: empty & < 1024b
+ String docid = String.valueOf(jo.get("docid"));
api.deleteDocument(docid);
}

0 comments on commit a8590e8

Please sign in to comment.