Skip to content
Browse files

add info retrieval.

  • Loading branch information...
1 parent 0e70c4f commit 139a78ccc66eb961772c54380e56c2f5b8afeec1 Robert Newson committed Mar 9, 2009
Showing with 37 additions and 0 deletions.
  1. +14 −0 README.md
  2. +23 −0 src/main/java/org/apache/couchdb/lucene/Search.java
View
14 README.md
@@ -208,6 +208,20 @@ And the same with sorting;
}
</pre>
+<h1>Fetching information about the index</h1>
+
+Calling couchdb-lucene without arguments returns a JSON object with information about the index.
+
+<pre>
+http://127.0.0.1:5984/enron/_fti
+</pre>
+
+returns;
+
+<pre>
+{"doc_count":517350,"doc_del_count":1,"disk_size":318543045}
+</pre>
+
<h1>Working With The Source</h1>
To develop "live", type "mvn dependency:unpack-dependencies" and change the external line to something like this;
View
23 src/main/java/org/apache/couchdb/lucene/Search.java
@@ -8,6 +8,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
/**
@@ -70,6 +71,20 @@ public static void main(final String[] args) throws Exception {
System.out.println(result);
continue;
}
+ // info.
+ if (query.keySet().isEmpty()) {
+ final JSONObject json = new JSONObject();
+ json.put("doc_count", reader.numDocs());
+ json.put("doc_del_count", reader.numDeletedDocs());
+ json.put("disk_size", size(reader.directory()));
+ reader.directory();
+
+ final JSONObject info = new JSONObject();
+ info.put("code", 200);
+ info.put("json", json);
+
+ System.out.println(info);
+ }
} catch (final Exception e) {
System.out.println(Utils.error(400, e.getMessage()));
}
@@ -81,4 +96,12 @@ public static void main(final String[] args) throws Exception {
}
}
+ private static long size(final Directory dir) throws IOException {
+ long result = 0;
+ for (final String name : dir.list()) {
+ result += dir.fileLength(name);
+ }
+ return result;
+ }
+
}

0 comments on commit 139a78c

Please sign in to comment.
Something went wrong with that request. Please try again.