Permalink
Browse files

Made it possible to post lucene queries to increase max length.

  • Loading branch information...
1 parent bc1bd8f commit 693e94235300fa5d25a4a7877be874931c3e0264 @hofmeister committed Apr 7, 2011
View
@@ -78,7 +78,10 @@ def respond(res, req, key):
else:
method = req["verb"]
- res.request(method, path, headers=req_headers)
+ if method == "POST":
+ res.request(method, path,req.get("body"),req_headers)
+ else:
+ res.request(method, path, headers=req_headers)
resp = res.getresponse()
resp_headers = {}
@@ -72,6 +72,8 @@
public final class DatabaseIndexer implements Runnable, ResponseHandler<Void> {
+
+
private class IndexState {
private final DocumentConverter converter;
@@ -455,8 +457,12 @@ public void run() {
close();
}
}
+ public void search(final HttpServletRequest req,
+ final HttpServletResponse resp) throws IOException, JSONException {
+ search(req.getParameter(LuceneServlet.QUERY_PARM), req, resp);
+ }
- public void search(final HttpServletRequest req,
+ public void search(final String query,final HttpServletRequest req,
final HttpServletResponse resp) throws IOException, JSONException {
final IndexState state = getState(req, resp);
if (state == null)
@@ -469,7 +475,7 @@ public void search(final HttpServletRequest req,
resp.setStatus(304);
return;
}
- for (final String queryString : getQueryStrings(req)) {
+ for (final String queryString : getQueryStrings(query)) {
final Analyzer analyzer = state.analyzer(req.getParameter("analyzer"));
final Operator operator = "and".equalsIgnoreCase(req.getParameter("default_operator"))
? Operator.AND : Operator.OR;
@@ -640,7 +646,10 @@ public void search(final HttpServletRequest req,
}
private String[] getQueryStrings(final HttpServletRequest req) {
- return Utils.splitOnCommas(req.getParameter("q"));
+ return getQueryStrings(req.getParameter("q"));
+ }
+ private String[] getQueryStrings(final String query) {
+ return Utils.splitOnCommas(query);
}
private void close() {
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
@@ -44,8 +45,10 @@
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 java.io.StringWriter;
public final class LuceneServlet extends HttpServlet {
+ public static final String QUERY_PARM = "q";
private static final Logger LOG = Logger.getLogger(LuceneServlet.class);
@@ -122,7 +125,7 @@ private Couch getCouch(final HttpServletRequest req) throws IOException {
final Configuration section = ini.getSection(new PathParts(req)
.getKey());
final String url = section.containsKey("url") ? section
- .getString("url") : null;
+ .getString("url") : "";
return new Couch(client, url);
}
@@ -188,7 +191,7 @@ private void doGetInternal(final HttpServletRequest req, final HttpServletRespon
return;
}
- if (req.getParameter("q") == null) {
+ if (req.getParameter(LuceneServlet.QUERY_PARM) == null) {
indexer.info(req, resp);
} else {
indexer.search(req, resp);
@@ -212,16 +215,46 @@ protected void doPost(final HttpServletRequest req,
private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException, JSONException {
+ DatabaseIndexer indexer;
switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
case 3:
if (req.getPathInfo().endsWith("/_cleanup")) {
cleanup(req, resp);
return;
}
break;
+ case 5:
+ indexer = getIndexer(req);
+ if (indexer == null) {
+ ServletUtils.sendJsonError(req, resp, 500, "error_creating_index");
+ return;
+ }
+ if (req.getContentLength() == 0) {
+ indexer.info(req, resp);
+ } else {
+ BufferedReader reader = req.getReader();
+ StringWriter writer = new StringWriter();
+
+ char[] buffer = new char[1024];
+ try {
+ int n;
+ while ((n = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, n);
+ }
+ } catch(Exception ex) {
+ log("Could not read input", ex);
+ } finally {
+ reader.close();
+ }
+ String query = writer.toString();
+
+ indexer.search(query,req, resp);
+ }
+ return;
case 6:
- final DatabaseIndexer indexer = getIndexer(req);
- indexer.admin(req, resp);
+ indexer = getIndexer(req);
+ if (indexer != null)
+ indexer.admin(req, resp);
return;
}
ServletUtils.sendJsonError(req, resp, 400, "bad_request");

0 comments on commit 693e942

Please sign in to comment.