Permalink
Browse files

Support for specifying analyzer as query parameter.

  • Loading branch information...
1 parent dcad252 commit 52d27f03c81b34934b73898d51b75f9ec7c1b601 @anandology anandology committed Nov 12, 2010
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
@@ -63,6 +63,7 @@
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.Analyzers;
import com.github.rnewson.couchdb.lucene.util.Constants;
import com.github.rnewson.couchdb.lucene.util.ServletUtils;
import com.github.rnewson.couchdb.lucene.util.StopWatch;
@@ -132,6 +133,12 @@ public Query parse(final String query) throws ParseException {
return parser.parse(query);
}
+ public Query parse(final String query, final Analyzer analyzer) throws ParseException {
+ final QueryParser parser = new CustomQueryParser(Constants.VERSION,
+ Constants.DEFAULT_FIELD, analyzer);
+ return parser.parse(query);
+ }
+
private synchronized void close() throws IOException {
if (reader != null)
reader.close();
@@ -467,7 +474,9 @@ public void search(final HttpServletRequest req,
return;
}
for (final String queryString : getQueryStrings(req)) {
- final Query q = state.parse(queryString);
+ final Analyzer analyzer = getAnalyzer(req, state.analyzer);
+ final Query q = state.parse(queryString, analyzer);
+
final JSONObject queryRow = new JSONObject();
queryRow.put("q", q.toString());
if (getBooleanParameter(req, "debug")) {
@@ -768,6 +777,11 @@ private void init() throws IOException {
private boolean isStaleOk(final HttpServletRequest req) {
return "ok".equals(req.getParameter("stale"));
}
+
+ private Analyzer getAnalyzer(final HttpServletRequest req, final Analyzer defaultAnalyzer) {
+ final String analyzer = req.getParameter("analyzer");
+ return analyzer == null ? defaultAnalyzer : Analyzers.getAnalyzer(analyzer);
+ }
private void maybeCommit() throws IOException {
if (now() - lastCommit >= getCommitInterval()) {

0 comments on commit 52d27f0

Please sign in to comment.