Permalink
Browse files

tolerate missing docs when using include_docs=true

  • Loading branch information...
Robert Newson
Robert Newson committed May 28, 2011
1 parent c7fad27 commit 279971cf4b941ace1c4eb8f5fb7cfbcc9640227f
@@ -579,10 +579,12 @@ public void search(final HttpServletRequest req,
final List<CouchDocument> fetched_docs = database
.getDocuments(fetch_ids);
for (int j = 0; j < max; j++) {
- rows.getJSONObject(j).put("doc",
- fetched_docs.get(j).asJson());
+ final CouchDocument doc = fetched_docs.get(j);
+ final JSONObject row = doc == null ?
+ new JSONObject("{\"error\":\"not_found\"}") :
+ doc.asJson();
+ rows.getJSONObject(j).put("doc", row);
}
-
}
stopWatch.lap("fetch");
@@ -157,7 +157,7 @@ public UUID getOrCreateUuid() throws IOException, JSONException {
private List<CouchDocument> toDocuments(final JSONObject json) throws JSONException {
final List<CouchDocument> result = new ArrayList<CouchDocument>();
for (final JSONObject doc : rows(json)) {
- result.add(new CouchDocument(doc));
+ result.add(doc == null ? null : new CouchDocument(doc));
}
return result;
}
@@ -166,7 +166,7 @@ public UUID getOrCreateUuid() throws IOException, JSONException {
final List<JSONObject> result = new ArrayList<JSONObject>();
final JSONArray rows = json.getJSONArray("rows");
for (int i = 0; i < rows.length(); i++) {
- result.add(rows.getJSONObject(i).getJSONObject("doc"));
+ result.add(rows.getJSONObject(i).optJSONObject("doc"));
}
return result;
}

0 comments on commit 279971c

Please sign in to comment.