Skip to content
Browse files

Merge branch 'master' of https://github.com/anandology/couchdb-lucene

…into anandology-master
  • Loading branch information...
2 parents 17647ea + 52d27f0 commit 09c018d976eb23b15cd1517b41a094e5f7172f77 Robert Newson committed Nov 12, 2010
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
View
16 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
@@ -62,6 +62,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;
@@ -131,6 +132,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();
@@ -468,7 +475,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")) {
@@ -774,6 +783,11 @@ private void init() throws IOException, JSONException {
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 09c018d

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