Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switch to org.json

  • Loading branch information...
commit f53e98ba8c95396560509167a1239cbf8145743c 1 parent fd58f69
@rnewson authored
Showing with 303 additions and 257 deletions.
  1. +3 −4 pom.xml
  2. +8 −8 src/main/java/com/github/rnewson/couchdb/lucene/CustomQueryParser.java
  3. +112 −106 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
  4. +20 −14 src/main/java/com/github/rnewson/couchdb/lucene/DocumentConverter.java
  5. +12 −8 src/main/java/com/github/rnewson/couchdb/lucene/JSONErrorHandler.java
  6. +35 −18 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
  7. +7 −8 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/Couch.java
  8. +4 −3 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/CouchDocument.java
  9. +21 −22 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/Database.java
  10. +4 −3 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/DatabaseInfo.java
  11. +8 −4 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/DesignDocument.java
  12. +6 −6 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/View.java
  13. +1 −2  src/main/java/com/github/rnewson/couchdb/lucene/couchdb/ViewSettings.java
  14. +10 −8 src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java
  15. +15 −5 src/main/java/com/github/rnewson/couchdb/lucene/util/ServletUtils.java
  16. +8 −3 src/main/java/com/github/rnewson/couchdb/lucene/util/Utils.java
  17. +5 −5 src/test/java/com/github/rnewson/couchdb/lucene/DocumentConverterTest.java
  18. +2 −7 src/test/java/com/github/rnewson/couchdb/lucene/JsonTest.java
  19. +7 −7 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/CouchDocumentTest.java
  20. +6 −6 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/DesignDocumentTest.java
  21. +4 −5 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/ViewTest.java
  22. +5 −5 src/test/java/com/github/rnewson/couchdb/lucene/util/AnalyzersTest.java
View
7 pom.xml
@@ -38,10 +38,9 @@
<version>1.6</version>
</dependency>
<dependency>
- <groupId>net.sf.json-lib</groupId>
- <artifactId>json-lib</artifactId>
- <version>2.2.3</version>
- <classifier>jdk15</classifier>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20090211</version>
</dependency>
<dependency>
<groupId>rhino</groupId>
View
16 src/main/java/com/github/rnewson/couchdb/lucene/CustomQueryParser.java
@@ -16,9 +16,6 @@
* limitations under the License.
*/
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
@@ -26,6 +23,9 @@
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.Version;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import com.github.rnewson.couchdb.lucene.couchdb.FieldType;
@@ -70,12 +70,12 @@ public static Sort toSort(final String sort) throws ParseException {
}
}
- public static String toString(final SortField[] sortFields) {
+ public static String toString(final SortField[] sortFields) throws JSONException {
final JSONArray result = new JSONArray();
for (final SortField field : sortFields) {
final JSONObject col = new JSONObject();
- col.element("field", field.getField());
- col.element("reverse", field.getReverse());
+ col.put("field", field.getField());
+ col.put("reverse", field.getReverse());
final String type;
switch (field.getType()) {
@@ -113,8 +113,8 @@ public static String toString(final SortField[] sortFields) {
type = "unknown";
break;
}
- col.element("type", type);
- result.add(col);
+ col.put("type", type);
+ result.put(col);
}
return result.toString();
}
View
218 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
@@ -14,18 +14,14 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
-import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import net.sf.json.JSON;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
import org.apache.commons.configuration.HierarchicalINIConfiguration;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -42,10 +38,10 @@
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexReader.FieldOption;
+import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.FieldDoc;
@@ -56,6 +52,9 @@
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.mozilla.javascript.ClassShutter;
import org.mozilla.javascript.Context;
@@ -93,7 +92,7 @@ public IndexState(final DocumentConverter converter,
}
public synchronized IndexReader borrowReader(final boolean staleOk)
- throws IOException {
+ throws IOException, JSONException {
blockForLatest(staleOk);
if (reader == null) {
etag = newEtag();
@@ -113,7 +112,7 @@ public synchronized IndexReader borrowReader(final boolean staleOk)
}
public IndexSearcher borrowSearcher(final boolean staleOk)
- throws IOException {
+ throws IOException, JSONException {
return new IndexSearcher(borrowReader(staleOk));
}
@@ -151,7 +150,7 @@ private synchronized boolean notModified(final HttpServletRequest req) {
return etag != null && etag.equals(req.getHeader("If-None-Match"));
}
- private void blockForLatest(final boolean staleOk) throws IOException {
+ private void blockForLatest(final boolean staleOk) throws IOException, JSONException {
if (staleOk) {
return;
}
@@ -191,9 +190,6 @@ public boolean visibleToScripts(final String fullClassName) {
}
}
- private static final JSONObject JSON_SUCCESS = JSONObject
- .fromObject("{\"ok\":true}");
-
public static File uuidDir(final File root, final UUID uuid) {
return new File(root, uuid.toString());
}
@@ -245,7 +241,7 @@ private static long now() {
public DatabaseIndexer(final HttpClient client, final File root,
final Database database, final HierarchicalINIConfiguration ini)
- throws IOException {
+ throws IOException, JSONException {
this.client = client;
this.root = root;
this.database = database;
@@ -255,7 +251,7 @@ public DatabaseIndexer(final HttpClient client, final File root,
}
public void admin(final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
+ final HttpServletResponse resp) throws IOException, JSONException {
final IndexState state = getState(req, resp);
if (state == null)
return;
@@ -265,7 +261,7 @@ public void admin(final HttpServletRequest req,
logger.info("Expunging deletes from " + state);
state.writer.expungeDeletes(false);
resp.setStatus(202);
- ServletUtils.writeJSON(req, resp, JSON_SUCCESS);
+ ServletUtils.writeJsonSuccess(req, resp);
return;
}
@@ -273,7 +269,7 @@ public void admin(final HttpServletRequest req,
logger.info("Optimizing " + state);
state.writer.optimize(false);
resp.setStatus(202);
- ServletUtils.writeJSON(req, resp, JSON_SUCCESS);
+ ServletUtils.writeJsonSuccess(req, resp);
return;
}
@@ -303,88 +299,93 @@ public Void handleResponse(final HttpResponse response)
continue loop;
}
- final JSONObject json = JSONObject.fromObject(line);
-
- if (json.has("error")) {
- logger.warn("Indexing stopping due to error: " + json);
- break loop;
- }
-
- if (json.has("last_seq")) {
- logger.warn("End of changes detected.");
- break loop;
- }
-
- final long seq = json.getLong("seq");
- final String id = json.getString("id");
- CouchDocument doc;
- if (json.has("doc")) {
- doc = new CouchDocument(json.getJSONObject("doc"));
- } else {
- // include_docs=true doesn't work prior to 0.11.
- try {
- doc = database.getDocument(id);
- } catch (final HttpResponseException e) {
- switch (e.getStatusCode()) {
- case HttpStatus.SC_NOT_FOUND:
- doc = CouchDocument.deletedDocument(id);
- break;
- default:
- logger.warn("Failed to fetch " + id);
- break loop;
- }
- }
- }
-
- if (id.startsWith("_design")) {
- if (seq > ddoc_seq) {
- logger.info("Exiting due to design document change.");
- break loop;
- }
- for (final IndexState state : states.values()) {
- state.setPendingSequence(seq);
- }
- continue loop;
- }
-
- if (doc.isDeleted()) {
- for (final IndexState state : states.values()) {
- state.writer.deleteDocuments(new Term("_id", id));
- state.setPendingSequence(seq);
- state.readerDirty = true;
- }
- } else {
- for (final Entry<View, IndexState> entry : states.entrySet()) {
- final View view = entry.getKey();
- final IndexState state = entry.getValue();
-
- if (seq > state.pending_seq) {
- final Document[] docs;
- try {
- docs = state.converter.convert(doc, view
- .getDefaultSettings(), database);
- } catch (final Exception e) {
- logger.warn(id + " caused " + e.getMessage());
- continue loop;
- }
-
- state.writer.deleteDocuments(new Term("_id", id));
- for (final Document d : docs) {
- state.writer.addDocument(d, view.getAnalyzer());
- state.writerDirty = true;
- }
- state.setPendingSequence(seq);
- state.readerDirty = true;
- }
- }
- }
+ try {
+ final JSONObject json = new JSONObject(line);
+
+ if (json.has("error")) {
+ logger.warn("Indexing stopping due to error: " + json);
+ break loop;
+ }
+
+ if (json.has("last_seq")) {
+ logger.warn("End of changes detected.");
+ break loop;
+ }
+
+ final long seq = json.getLong("seq");
+ final String id = json.getString("id");
+ CouchDocument doc;
+ if (json.has("doc")) {
+ doc = new CouchDocument(json.getJSONObject("doc"));
+ } else {
+ // include_docs=true doesn't work prior to 0.11.
+ try {
+ doc = database.getDocument(id);
+ } catch (final HttpResponseException e) {
+ switch (e.getStatusCode()) {
+ case HttpStatus.SC_NOT_FOUND:
+ doc = CouchDocument.deletedDocument(id);
+ break;
+ default:
+ logger.warn("Failed to fetch " + id);
+ break loop;
+ }
+ }
+ }
+
+ if (id.startsWith("_design")) {
+ if (seq > ddoc_seq) {
+ logger.info("Exiting due to design document change.");
+ break loop;
+ }
+ for (final IndexState state : states.values()) {
+ state.setPendingSequence(seq);
+ }
+ continue loop;
+ }
+
+ if (doc.isDeleted()) {
+ for (final IndexState state : states.values()) {
+ state.writer.deleteDocuments(new Term("_id", id));
+ state.setPendingSequence(seq);
+ state.readerDirty = true;
+ }
+ } else {
+ for (final Entry<View, IndexState> entry : states.entrySet()) {
+ final View view = entry.getKey();
+ final IndexState state = entry.getValue();
+
+ if (seq > state.pending_seq) {
+ final Document[] docs;
+ try {
+ docs = state.converter.convert(doc, view
+ .getDefaultSettings(), database);
+ } catch (final Exception e) {
+ logger.warn(id + " caused " + e.getMessage());
+ continue loop;
+ }
+
+ state.writer.deleteDocuments(new Term("_id", id));
+ for (final Document d : docs) {
+ state.writer.addDocument(d, view.getAnalyzer());
+ state.writerDirty = true;
+ }
+ state.setPendingSequence(seq);
+ state.readerDirty = true;
+ }
+ }
+ }
+ } catch (final JSONException e) {
+ logger.error("JSON exception in changes loop", e);
+ break loop;
+ }
}
req.abort();
return null;
}
public void info(final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
+ final HttpServletResponse resp) throws IOException, JSONException {
final IndexState state = getState(req, resp);
if (state == null)
return;
@@ -400,7 +401,7 @@ public void info(final HttpServletRequest req,
if (((String) field).startsWith("_")) {
continue;
}
- fields.add(field);
+ fields.put(field);
}
result.put("fields", fields);
result.put("last_modified", Long.toString(IndexReader
@@ -454,7 +455,7 @@ public void run() {
}
public void search(final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
+ final HttpServletResponse resp) throws IOException, JSONException {
final IndexState state = getState(req, resp);
if (state == null)
return;
@@ -486,7 +487,7 @@ public void search(final HttpServletRequest req,
rewritten_q.extractTerms(terms);
for (final Object term : terms) {
final int freq = searcher.docFreq((Term) term);
- freqs.put(term, freq);
+ freqs.put(term.toString(), freq);
}
queryRow.put("freqs", freqs);
} else {
@@ -537,12 +538,12 @@ public void search(final HttpServletRequest req,
final Object obj = fields.get(name);
if (obj instanceof String) {
final JSONArray arr = new JSONArray();
- arr.add(obj);
- arr.add(value);
+ arr.put(obj);
+ arr.put(value);
fields.put(name, arr);
} else {
assert obj instanceof JSONArray;
- ((JSONArray) obj).add(value);
+ ((JSONArray) obj).put(value);
}
}
}
@@ -560,10 +561,10 @@ public void search(final HttpServletRequest req,
if (include_docs) {
fetch_ids[i - skip] = doc.get("_id");
}
- if (fields.size() > 0) {
+ if (fields.length() > 0) {
row.put("fields", fields);
}
- rows.add(row);
+ rows.put(row);
}
// Fetch documents (if requested).
if (include_docs && fetch_ids.length > 0) {
@@ -592,7 +593,7 @@ public void search(final HttpServletRequest req,
}
queryRow.put("rows", rows);
}
- result.add(queryRow);
+ result.put(queryRow);
}
} catch (final ParseException e) {
ServletUtils.sendJSONError(req, resp, 400, "Bad query syntax: "
@@ -606,13 +607,18 @@ public void search(final HttpServletRequest req,
resp.setHeader("Cache-Control", "must-revalidate");
ServletUtils.setResponseContentTypeAndEncoding(req, resp);
- final JSON json = result.size() > 1 ? result : result.getJSONObject(0);
+ final Object json = result.length() > 1 ? result : result.getJSONObject(0);
final String callback = req.getParameter("callback");
final String body;
if (callback != null) {
body = String.format("%s(%s)", callback, json);
} else {
- body = json.toString(getBooleanParameter(req, "debug") ? 2 : 0);
+ final int indentFactor = getBooleanParameter(req, "debug") ? 2 : 0;
+ if (json instanceof JSONObject) {
+ body = ((JSONObject)json).toString(indentFactor);
+ } else {
+ body = ((JSONArray)json).toString(indentFactor);
+ }
}
final Writer writer = resp.getWriter();
@@ -690,7 +696,7 @@ private int getIntParameter(final HttpServletRequest req,
}
private IndexState getState(final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
+ final HttpServletResponse resp) throws IOException, JSONException {
final View view = paths.get(toPath(req));
if (view == null) {
ServletUtils.sendJSONError(req, resp, 400, "no_such_view");
@@ -722,7 +728,7 @@ private long getUpdateSequence(final Map<String, String> userData) {
return 0L;
}
- private void init() throws IOException {
+ private void init() throws IOException, JSONException {
this.uuid = database.getOrCreateUuid();
this.context = Context.enter();
View
34 src/main/java/com/github/rnewson/couchdb/lucene/DocumentConverter.java
@@ -18,13 +18,14 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
+import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.ParseException;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.JavaScriptException;
@@ -49,7 +50,7 @@
private final Function viewFun;
private final ScriptableObject scope;
- public DocumentConverter(final Context context, final View view) throws IOException {
+ public DocumentConverter(final Context context, final View view) throws IOException, JSONException {
this.context = context;
scope = context.initStandardObjects();
@@ -74,7 +75,7 @@ public DocumentConverter(final Context context, final View view) throws IOExcept
public Document[] convert(
final CouchDocument doc,
final ViewSettings defaults,
- final Database database) throws IOException, ParseException {
+ final Database database) throws IOException, ParseException, JSONException {
final Object result;
final Scriptable scriptable = convertObject(doc.asJson());
@@ -114,32 +115,37 @@ public DocumentConverter(final Context context, final View view) throws IOExcept
return null;
}
- private Object convert(final Object obj) {
+ private Object convert(final Object obj) throws JSONException {
if (obj instanceof JSONArray) {
return convertArray((JSONArray) obj);
- } else if (obj instanceof JSONObject) {
+ } else if (obj == JSONObject.NULL) {
+ return null;
+ }
+ else if (obj instanceof JSONObject) {
return convertObject((JSONObject) obj);
} else {
return obj;
}
}
- private Scriptable convertArray(final JSONArray array) {
- final Scriptable result = context.newArray(scope, array.size());
- for (int i = 0, max = array.size(); i < max; i++) {
+ private Scriptable convertArray(final JSONArray array) throws JSONException {
+ final Scriptable result = context.newArray(scope, array.length());
+ for (int i = 0, max = array.length(); i < max; i++) {
ScriptableObject.putProperty(result, i, convert(array.get(i)));
}
return result;
}
- private Scriptable convertObject(final JSONObject obj) {
- if (obj.isNullObject()) {
+ private Scriptable convertObject(final JSONObject obj) throws JSONException {
+ if (obj == null) {
return null;
}
final Scriptable result = context.newObject(scope);
- for (final Object key : obj.keySet()) {
+ final Iterator<?> it = obj.keys();
+ while (it.hasNext()) {
+ final String key = (String) it.next();
final Object value = obj.get(key);
- ScriptableObject.putProperty(result, (String) key, convert(value));
+ ScriptableObject.putProperty(result, key, convert(value));
}
return result;
}
View
20 src/main/java/com/github/rnewson/couchdb/lucene/JSONErrorHandler.java
@@ -21,8 +21,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import net.sf.json.JSONObject;
-
+import org.json.JSONException;
+import org.json.JSONObject;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.handler.ErrorHandler;
@@ -40,12 +40,16 @@ public void handle(String target, HttpServletRequest request, HttpServletRespons
HttpConnection connection = HttpConnection.getCurrentConnection();
connection.getRequest().setHandled(true);
final String reason = connection.getResponse().getReason();
- if (reason.startsWith("{")) {
- ServletUtils.sendJSONError(request, response, connection.getResponse().getStatus(),
- JSONObject.fromObject(reason));
- } else {
- ServletUtils.sendJSONError(request, response, connection.getResponse().getStatus(),
- reason);
+ try {
+ if (reason.startsWith("{")) {
+ ServletUtils.sendJSONError(request, response, connection.getResponse().getStatus(),
+ new JSONObject(reason));
+ } else {
+ ServletUtils.sendJSONError(request, response, connection.getResponse().getStatus(),
+ reason);
+ }
+ } catch (final JSONException e) {
+ response.sendError(500);
}
}
View
53 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -29,26 +29,25 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import net.sf.json.JSONObject;
-
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.HierarchicalINIConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.HttpClient;
import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import com.github.rnewson.couchdb.lucene.couchdb.Couch;
import com.github.rnewson.couchdb.lucene.couchdb.Database;
import com.github.rnewson.couchdb.lucene.couchdb.DesignDocument;
import com.github.rnewson.couchdb.lucene.couchdb.View;
import com.github.rnewson.couchdb.lucene.util.ServletUtils;
+import com.github.rnewson.couchdb.lucene.util.Utils;
public final class LuceneServlet extends HttpServlet {
- private static final JSONObject JSON_SUCCESS = JSONObject
- .fromObject("{\"ok\":true}");
-
private static final Logger LOG = Logger.getLogger(LuceneServlet.class);
private static final long serialVersionUID = 1L;
@@ -71,12 +70,12 @@ public LuceneServlet(final HttpClient client, final File root,
}
private void cleanup(final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
+ final HttpServletResponse resp) throws IOException, JSONException {
final Couch couch = getCouch(req);
final Set<String> dbKeep = new HashSet<String>();
-
- for (final String dbname : couch.getAllDatabases()) {
- final Database db = couch.getDatabase(dbname);
+ final JSONArray databases = couch.getAllDatabases();
+ for (int i=0; i< databases.length(); i++) {
+ final Database db = couch.getDatabase(databases.getString(i));
final UUID uuid = db.getUuid();
if (uuid == null) {
continue;
@@ -117,7 +116,7 @@ private void cleanup(final HttpServletRequest req,
}
resp.setStatus(202);
- ServletUtils.writeJSON(req, resp, JSON_SUCCESS);
+ ServletUtils.writeJsonSuccess(req, resp);
}
private Couch getCouch(final HttpServletRequest req) throws IOException {
@@ -129,7 +128,7 @@ private Couch getCouch(final HttpServletRequest req) throws IOException {
}
private synchronized DatabaseIndexer getIndexer(final Database database)
- throws IOException {
+ throws IOException, JSONException {
DatabaseIndexer result = indexers.get(database);
Thread thread = threads.get(database);
if (result == null || thread == null || !thread.isAlive()) {
@@ -149,7 +148,7 @@ private synchronized DatabaseIndexer getIndexer(final Database database)
}
private DatabaseIndexer getIndexer(final HttpServletRequest req)
- throws IOException {
+ throws IOException, JSONException {
final Couch couch = getCouch(req);
final Database database = couch.getDatabase(new PathParts(req)
.getDatabaseName());
@@ -158,19 +157,28 @@ private DatabaseIndexer getIndexer(final HttpServletRequest req)
private void handleWelcomeReq(final HttpServletRequest req,
final HttpServletResponse resp) throws ServletException,
- IOException {
+ IOException, JSONException {
final Package p = this.getClass().getPackage();
final JSONObject welcome = new JSONObject();
welcome.put("couchdb-lucene", "Welcome");
welcome.put("version", p.getImplementationVersion());
- ServletUtils.writeJSON(req, resp, welcome);
+ ServletUtils.writeJson(req, resp, welcome);
}
@Override
protected void doGet(final HttpServletRequest req,
final HttpServletResponse resp) throws ServletException,
IOException {
- switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
+ try {
+ doGetInternal(req, resp);
+ } catch (final JSONException e) {
+ resp.sendError(500);
+ }
+ }
+
+ private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp)
+ throws ServletException, IOException, JSONException {
+ switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
case 1:
handleWelcomeReq(req, resp);
return;
@@ -190,13 +198,22 @@ protected void doGet(final HttpServletRequest req,
}
ServletUtils.sendJSONError(req, resp, 400, "bad_request");
- }
+ }
@Override
protected void doPost(final HttpServletRequest req,
final HttpServletResponse resp) throws ServletException,
IOException {
- switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
+ try {
+ doPostInternal(req, resp);
+ } catch (final JSONException e) {
+ resp.sendError(500);
+ }
+ }
+
+ private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp)
+ throws IOException, JSONException {
+ switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
case 3:
if (req.getPathInfo().endsWith("/_cleanup")) {
cleanup(req, resp);
@@ -209,6 +226,6 @@ protected void doPost(final HttpServletRequest req,
return;
}
ServletUtils.sendJSONError(req, resp, 400, "bad_request");
- }
+ }
}
View
15 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/Couch.java
@@ -18,10 +18,10 @@
import java.io.IOException;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
import org.apache.http.client.HttpClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
/**
* Simple Java API access to CouchDB.
@@ -40,14 +40,13 @@ public Couch(final HttpClient httpClient, final String url)
this.url = url.endsWith("/") ? url : url + "/";
}
- public final String[] getAllDatabases() throws IOException {
+ public final JSONArray getAllDatabases() throws IOException, JSONException {
final String response = HttpUtils.get(httpClient, url + "_all_dbs");
- final JSONArray arr = JSONArray.fromObject(response);
- return (String[]) arr.toArray(new String[0]);
+ return new JSONArray(response);
}
- public final JSONObject getInfo() throws IOException {
- return JSONObject.fromObject(HttpUtils.get(httpClient, url));
+ public final JSONObject getInfo() throws IOException, JSONException {
+ return new JSONObject(HttpUtils.get(httpClient, url));
}
public Database getDatabase(final String dbname) throws IOException {
View
7 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/CouchDocument.java
@@ -16,7 +16,8 @@
* limitations under the License.
*/
-import net.sf.json.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
public class CouchDocument {
@@ -26,7 +27,7 @@
private static final String DELETED = "_deleted";
- public static CouchDocument deletedDocument(final String id) {
+ public static CouchDocument deletedDocument(final String id) throws JSONException {
final JSONObject json = new JSONObject();
json.put(ID, id);
json.put(DELETED, true);
@@ -40,7 +41,7 @@ public CouchDocument(final JSONObject json) {
this.json = json;
}
- public String getId() {
+ public String getId() throws JSONException {
return json.getString(ID);
}
View
43 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/Database.java
@@ -22,15 +22,15 @@
import java.util.List;
import java.util.UUID;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import com.github.rnewson.couchdb.lucene.util.Utils;
@@ -53,29 +53,29 @@ public boolean delete() throws IOException {
return HttpUtils.delete(httpClient, url) == 200;
}
- public List<DesignDocument> getAllDesignDocuments() throws IOException {
+ public List<DesignDocument> getAllDesignDocuments() throws IOException, JSONException {
final String body = HttpUtils.get(httpClient, String
.format("%s_all_docs?startkey=%s&endkey=%s&include_docs=true",
url, Utils.urlEncode("\"_design\""), Utils
.urlEncode("\"_design0\"")));
- final JSONObject json = JSONObject.fromObject(body);
+ final JSONObject json = new JSONObject(body);
return toDesignDocuments(json);
}
- public CouchDocument getDocument(final String id) throws IOException {
+ public CouchDocument getDocument(final String id) throws IOException, JSONException {
final String response = HttpUtils.get(httpClient, url
+ Utils.urlEncode(id));
- return new CouchDocument(JSONObject.fromObject(response));
+ return new CouchDocument(new JSONObject(response));
}
- public DesignDocument getDesignDocument(final String id) throws IOException {
+ public DesignDocument getDesignDocument(final String id) throws IOException, JSONException {
final String response = HttpUtils.get(httpClient, url
+ Utils.urlEncode(id));
- return new DesignDocument(JSONObject.fromObject(response));
+ return new DesignDocument(new JSONObject(response));
}
public List<CouchDocument> getDocuments(final String... ids)
- throws IOException {
+ throws IOException, JSONException {
if (ids.length == 0) {
return Collections.emptyList();
}
@@ -83,19 +83,18 @@ public DesignDocument getDesignDocument(final String id) throws IOException {
final JSONArray keys = new JSONArray();
for (final String id : ids) {
assert id != null;
- keys.add(id);
+ keys.put(id);
}
final JSONObject req = new JSONObject();
- req.element("keys", keys);
+ req.put("keys", keys);
final String body = HttpUtils.post(httpClient, url
+ "_all_docs?include_docs=true", req.toString());
- final JSONObject json = JSONObject.fromObject(body);
- return toDocuments(json);
+ return toDocuments(new JSONObject(body));
}
- public DatabaseInfo getInfo() throws IOException {
- return new DatabaseInfo(JSONObject.fromObject(HttpUtils.get(httpClient,
+ public DatabaseInfo getInfo() throws IOException, JSONException {
+ return new DatabaseInfo(new JSONObject(HttpUtils.get(httpClient,
url)));
}
@@ -119,7 +118,7 @@ public boolean saveDocument(final String id, final String body)
return HttpUtils.put(httpClient, url + Utils.urlEncode(id), body) == 201;
}
- public UUID getUuid() throws IOException {
+ public UUID getUuid() throws IOException, JSONException {
try {
final CouchDocument local = getDocument("_local/lucene");
return UUID.fromString(local.asJson().getString("uuid"));
@@ -138,7 +137,7 @@ public void createUuid() throws IOException {
saveDocument("_local/lucene", String.format("{\"uuid\":\"%s\"}", uuid));
}
- public UUID getOrCreateUuid() throws IOException {
+ public UUID getOrCreateUuid() throws IOException, JSONException {
final UUID result = getUuid();
if (result != null) {
return result;
@@ -147,7 +146,7 @@ public UUID getOrCreateUuid() throws IOException {
return getUuid();
}
- private List<DesignDocument> toDesignDocuments(final JSONObject json) {
+ private List<DesignDocument> toDesignDocuments(final JSONObject json) throws JSONException {
final List<DesignDocument> result = new ArrayList<DesignDocument>();
for (final JSONObject doc : rows(json)) {
result.add(new DesignDocument(doc));
@@ -155,7 +154,7 @@ public UUID getOrCreateUuid() throws IOException {
return result;
}
- private List<CouchDocument> toDocuments(final JSONObject json) {
+ 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));
@@ -163,10 +162,10 @@ public UUID getOrCreateUuid() throws IOException {
return result;
}
- private List<JSONObject> rows(final JSONObject json) {
+ private List<JSONObject> rows(final JSONObject json) throws JSONException {
final List<JSONObject> result = new ArrayList<JSONObject>();
final JSONArray rows = json.getJSONArray("rows");
- for (int i = 0; i < rows.size(); i++) {
+ for (int i = 0; i < rows.length(); i++) {
result.add(rows.getJSONObject(i).getJSONObject("doc"));
}
return result;
View
7 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/DatabaseInfo.java
@@ -1,6 +1,7 @@
package com.github.rnewson.couchdb.lucene.couchdb;
-import net.sf.json.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
public class DatabaseInfo {
@@ -10,11 +11,11 @@ public DatabaseInfo(final JSONObject json) {
this.json = json;
}
- public long getUpdateSequence() {
+ public long getUpdateSequence() throws JSONException {
return json.getLong("update_seq");
}
- public String getName() {
+ public String getName() throws JSONException {
return json.getString("db_name");
}
View
12 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/DesignDocument.java
@@ -18,15 +18,17 @@
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
-import net.sf.json.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
public class DesignDocument extends CouchDocument {
private final JSONObject fulltext;
- public DesignDocument(final JSONObject json) {
+ public DesignDocument(final JSONObject json) throws JSONException {
super(json);
if (!getId().startsWith("_design/")) {
throw new IllegalArgumentException(json
@@ -35,7 +37,7 @@ public DesignDocument(final JSONObject json) {
fulltext = json.optJSONObject("fulltext");
}
- public DesignDocument(final CouchDocument doc) {
+ public DesignDocument(final CouchDocument doc) throws JSONException {
this(doc.json);
}
@@ -50,7 +52,9 @@ public View getView(final String name) {
if (fulltext == null)
return Collections.emptyMap();
final Map<String, View> result = new HashMap<String, View>();
- for (final Object key : fulltext.keySet()) {
+ final Iterator<?> it = fulltext.keys();
+ while (it.hasNext()) {
+ final Object key = it.next();
final String name = (String) key;
final View view = getView(name);
if (view != null) {
View
12 src/main/java/com/github/rnewson/couchdb/lucene/couchdb/View.java
@@ -20,10 +20,10 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import net.sf.json.JSONObject;
-
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.analysis.Analyzer;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ScriptableObject;
@@ -49,22 +49,22 @@ public View(final JSONObject json) {
this.json = json;
}
- public Analyzer getAnalyzer() {
+ public Analyzer getAnalyzer() throws JSONException {
return Analyzers
.getAnalyzer(json.optString(ANALYZER, DEFAULT_ANALYZER));
}
- public ViewSettings getDefaultSettings() {
+ public ViewSettings getDefaultSettings() throws JSONException {
return json.has(DEFAULTS) ? new ViewSettings(json
.getJSONObject(DEFAULTS)) : ViewSettings.getDefaultSettings();
}
- public String getFunction() {
+ public String getFunction() throws JSONException {
return trim(json.getString(INDEX));
}
public Function compileFunction(final Context context,
- ScriptableObject scope) {
+ ScriptableObject scope) throws JSONException {
return context.compileFunction(scope, getFunction(), null, 0, null);
}
View
3  src/main/java/com/github/rnewson/couchdb/lucene/couchdb/ViewSettings.java
@@ -1,10 +1,9 @@
package com.github.rnewson.couchdb.lucene.couchdb;
-import net.sf.json.JSONObject;
-
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.Field.TermVector;
+import org.json.JSONObject;
import org.mozilla.javascript.NativeObject;
import com.github.rnewson.couchdb.lucene.util.Constants;
View
18 src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java
@@ -17,8 +17,7 @@
*/
import java.io.Reader;
-
-import net.sf.json.JSONObject;
+import java.util.Iterator;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -38,6 +37,8 @@
import org.apache.lucene.analysis.ru.RussianAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.th.ThaiAnalyzer;
+import org.json.JSONException;
+import org.json.JSONObject;
public enum Analyzers {
@@ -97,12 +98,13 @@ public Analyzer newAnalyzer(final String args) {
},
PERFIELD {
@Override
- public Analyzer newAnalyzer(final String args) {
- final JSONObject json = JSONObject.fromObject(args == null ? "{}" : args);
+ public Analyzer newAnalyzer(final String args) throws JSONException {
+ final JSONObject json = new JSONObject(args == null ? "{}" : args);
final Analyzer defaultAnalyzer = Analyzers.getAnalyzer(json.optString(Constants.DEFAULT_FIELD, "standard"));
final PerFieldAnalyzerWrapper result = new PerFieldAnalyzerWrapper(defaultAnalyzer);
- for (final Object obj : json.keySet()) {
- final String key = obj.toString();
+ final Iterator<?> it = json.keys();
+ while (it.hasNext()) {
+ final String key = it.next().toString();
if (Constants.DEFAULT_FIELD.equals(key))
continue;
result.addAnalyzer(key, Analyzers.getAnalyzer(json.getString(key)));
@@ -153,13 +155,13 @@ public TokenStream tokenStream(final String fieldName, final Reader reader) {
}
}
- public static Analyzer getAnalyzer(final String str) {
+ public static Analyzer getAnalyzer(final String str) throws JSONException {
final String[] parts = str.split(":", 2);
final String name = parts[0].toUpperCase();
final String args = parts.length == 2 ? parts[1] : null;
return Analyzers.valueOf(name).newAnalyzer(args);
}
- public abstract Analyzer newAnalyzer(final String args);
+ public abstract Analyzer newAnalyzer(final String args) throws JSONException;
}
View
20 src/main/java/com/github/rnewson/couchdb/lucene/util/ServletUtils.java
@@ -22,10 +22,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.mortbay.jetty.HttpHeaders;
-import net.sf.json.JSONObject;
-
public final class ServletUtils {
public static boolean getBooleanParameter(final HttpServletRequest req, final String parameterName) {
@@ -48,14 +48,14 @@ public static String getParameter(final HttpServletRequest req, final String par
}
public static void sendJSONError(final HttpServletRequest request, final HttpServletResponse response, final int code,
- final String reason) throws IOException {
+ final String reason) throws IOException, JSONException {
final JSONObject obj = new JSONObject();
obj.put("reason", reason);
sendJSONError(request, response, code, obj);
}
public static void sendJSONError(final HttpServletRequest request, final HttpServletResponse response, final int code,
- final JSONObject error) throws IOException {
+ final JSONObject error) throws IOException, JSONException {
error.put("code", code);
setResponseContentTypeAndEncoding(request, response);
@@ -84,7 +84,7 @@ public static void setResponseContentTypeAndEncoding(final HttpServletRequest re
resp.setCharacterEncoding("utf-8");
}
- public static void writeJSON(final HttpServletRequest req, final HttpServletResponse resp, final JSONObject json) throws IOException {
+ public static void writeJson(final HttpServletRequest req, final HttpServletResponse resp, final JSONObject json) throws IOException {
setResponseContentTypeAndEncoding(req, resp);
final Writer writer = resp.getWriter();
try {
@@ -93,5 +93,15 @@ public static void writeJSON(final HttpServletRequest req, final HttpServletResp
writer.close();
}
}
+
+ public static void writeJsonSuccess(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
+ setResponseContentTypeAndEncoding(req, resp);
+ final Writer writer = resp.getWriter();
+ try {
+ writer.write("{\"ok\", true}\r\n");
+ } finally {
+ writer.close();
+ }
+ }
}
View
11 src/main/java/com/github/rnewson/couchdb/lucene/util/Utils.java
@@ -16,18 +16,18 @@
* limitations under the License.
*/
-
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
-
import org.apache.log4j.Logger;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.store.Directory;
+import org.json.JSONException;
+import org.json.JSONObject;
public class Utils {
@@ -44,7 +44,11 @@ public static Field text(final String name, final String value, final boolean st
}
public static Field token(final String name, final String value, final boolean store) {
- return new Field(name, value, store ? Store.YES : Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
+ return new Field(
+ name,
+ value,
+ store ? Store.YES : Store.NO,
+ Field.Index.NOT_ANALYZED_NO_NORMS);
}
public static String urlEncode(final String path) {
@@ -65,6 +69,7 @@ public static long directorySize(final Directory dir) throws IOException {
/**
* Split a string on commas but respect commas inside quotes.
+ *
* @param str
* @return
*/
View
10 src/test/java/com/github/rnewson/couchdb/lucene/DocumentConverterTest.java
@@ -6,10 +6,10 @@
import java.util.TimeZone;
-import net.sf.json.JSONObject;
-
import org.apache.lucene.document.Document;
import org.apache.lucene.document.NumericField;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -281,15 +281,15 @@ public void testConditionalOnNulls() throws Exception {
assertThat(result.length, is(0));
}
- private CouchDocument doc(final String json) {
- return new CouchDocument(JSONObject.fromObject(json));
+ private CouchDocument doc(final String json) throws JSONException {
+ return new CouchDocument(new JSONObject(json));
}
private ViewSettings settings() {
return ViewSettings.getDefaultSettings();
}
- private View view(final String fun) {
+ private View view(final String fun) throws JSONException {
final JSONObject json = new JSONObject();
json.put("index", fun);
return new View(json);
View
9 src/test/java/com/github/rnewson/couchdb/lucene/JsonTest.java
@@ -1,11 +1,6 @@
package com.github.rnewson.couchdb.lucene;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-import net.sf.json.JSONObject;
-
+import org.json.JSONObject;
import org.junit.Test;
public class JsonTest {
@@ -13,7 +8,7 @@
@Test
public void testEscapedChars() throws Exception {
final String str = "{\"seq\":1503,\"id\":\"11dca825e8b19e40bd675345e05afa24\",\"changes\":[{\"rev\":\"2-bb1fba3e33ed2e8b78412fe27c8c6474\"}],\"doc\":{\"_id\":\"11dca825e8b19e40bd675345e05afa24\",\"_rev\":\"2-bb1fba3e33ed2e8b78412fe27c8c6474\",\"query_params\":{\"{\\\"action\\\":\\\"answer\\\",\\\"session-id\\\":41,\\\"answer\\\":5}\":\"\"},\"stack_trace\":\" File \\\"/usr/local/lib/python2.6/dist-packages/Django-1.2.1-py2.6.egg/django/core/handlers/base.py\\\", line 95, in get_response\\n response = middleware_method(request, callback, callback_args, callback_kwargs)\\n File \\\"/var/src/bhoma/bhoma/middleware.py\\\", line 37, in process_view\\n return login_required(view_func)(request, *view_args, **view_kwargs)\\n File \\\"/usr/local/lib/python2.6/dist-packages/Django-1.2.1-py2.6.egg/django/contrib/auth/decorators.py\\\", line 25, in _wrapped_view\\n return view_func(request, *args, **kwargs)\\n File \\\"/var/src/bhoma/bhoma/apps/xforms/views.py\\\", line 74, in player_proxy\\n response, errors = post_data(data, settings.XFORMS_PLAYER_URL, content_type=\\\"text/json\\\")\\n File \\\"/var/src/bhoma/bhoma/utils/post.py\\\", line 34, in post_data\\n\",\"doc_type\":\"ExceptionRecord\",\"url\":\"http://10.10.10.10/xforms/player_proxy\",\"clinic_id\":\"5010110\",\"date\":\"2010-09-08T14:39:11Z\",\"message\":\"[Errno 24] Too many open files: '/tmp/tmp8xIQb7'\",\"type\":\"<type 'exceptions.IOError'>\"}}";
- assertThat(JSONObject.fromObject(str), is(notNullValue()));
+ new JSONObject(str);
}
}
View
14 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/CouchDocumentTest.java
@@ -2,8 +2,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import net.sf.json.JSONObject;
+import org.json.JSONObject;
import org.junit.Test;
/**
@@ -25,19 +25,19 @@
public class CouchDocumentTest {
@Test(expected = IllegalArgumentException.class)
- public void notValidDocument() {
- new CouchDocument(JSONObject.fromObject("{}"));
+ public void notValidDocument() throws Exception {
+ new CouchDocument(new JSONObject("{}"));
}
@Test
- public void validDocument() {
- final CouchDocument doc = new CouchDocument(JSONObject.fromObject("{_id:\"hello\"}"));
+ public void validDocument() throws Exception {
+ final CouchDocument doc = new CouchDocument(new JSONObject("{_id:\"hello\"}"));
assertThat(doc.getId(), is("hello"));
}
@Test
- public void asJson() {
- final JSONObject json = JSONObject.fromObject("{_id:\"hello\"}");
+ public void asJson() throws Exception {
+ final JSONObject json = new JSONObject("{_id:\"hello\"}");
final CouchDocument doc = new CouchDocument(json);
assertThat(doc.asJson(), is(json));
}
View
12 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/DesignDocumentTest.java
@@ -3,8 +3,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
-import net.sf.json.JSONObject;
+import org.json.JSONObject;
import org.junit.Test;
/**
@@ -26,18 +26,18 @@
public class DesignDocumentTest {
@Test(expected = IllegalArgumentException.class)
- public void notDesignDocument() {
- new DesignDocument(JSONObject.fromObject("{_id:\"hello\"}"));
+ public void notDesignDocument() throws Exception {
+ new DesignDocument(new JSONObject("{_id:\"hello\"}"));
}
@Test
- public void noViews() {
- final DesignDocument ddoc = new DesignDocument(JSONObject.fromObject("{_id:\"_design/hello\"}"));
+ public void noViews() throws Exception {
+ final DesignDocument ddoc = new DesignDocument(new JSONObject("{_id:\"_design/hello\"}"));
assertThat(ddoc.getAllViews().size(), is(0));
}
@Test
- public void views() {
+ public void views() throws Exception {
final JSONObject view = new JSONObject();
view.put("index", "function(doc) { return null; }");
View
9 src/test/java/com/github/rnewson/couchdb/lucene/couchdb/ViewTest.java
@@ -1,7 +1,6 @@
package com.github.rnewson.couchdb.lucene.couchdb;
-import net.sf.json.JSONObject;
-
+import org.json.JSONObject;
import org.junit.Test;
/**
@@ -23,12 +22,12 @@
public class ViewTest {
@Test(expected = IllegalArgumentException.class)
- public void noIndex() {
- new View(JSONObject.fromObject("{}"));
+ public void noIndex() throws Exception {
+ new View(new JSONObject("{}"));
}
@Test
- public void index() {
+ public void index() throws Exception {
final JSONObject json = new JSONObject();
json.put("index", "function(doc) { return null; }");
View
10 src/test/java/com/github/rnewson/couchdb/lucene/util/AnalyzersTest.java
@@ -14,22 +14,22 @@
public class AnalyzersTest {
@Test
- public void testStandard() {
+ public void testStandard() throws Exception {
assertThat(Analyzers.getAnalyzer("standard"), is(StandardAnalyzer.class));
}
@Test
- public void testFrench() {
+ public void testFrench() throws Exception {
assertThat(Analyzers.getAnalyzer("french"), is(FrenchAnalyzer.class));
}
@Test
- public void testWhitespace() {
+ public void testWhitespace() throws Exception {
assertThat(Analyzers.getAnalyzer("whitespace"), is(WhitespaceAnalyzer.class));
}
@Test
- public void testPerField() {
+ public void testPerField() throws Exception {
final Analyzer analyzer = Analyzers.getAnalyzer("perfield:{name:\"standard\",age:\"keyword\"}");
assertThat(analyzer, is(PerFieldAnalyzerWrapper.class));
assertThat(analyzer.toString(), containsString("default=org.apache.lucene.analysis.standard.StandardAnalyzer"));
@@ -38,7 +38,7 @@ public void testPerField() {
}
@Test
- public void testPerFieldDefault() {
+ public void testPerFieldDefault() throws Exception {
final Analyzer analyzer = Analyzers.getAnalyzer("perfield:{default:\"keyword\"}");
assertThat(analyzer, is(PerFieldAnalyzerWrapper.class));
assertThat(analyzer.toString(), containsString("default=org.apache.lucene.analysis.KeywordAnalyzer"));
Please sign in to comment.
Something went wrong with that request. Please try again.