Skip to content
Browse files

allow default_operator=and. Closes #95

  • Loading branch information...
1 parent 2ff52b0 commit bba040b8a743de60c936d4e687c66a4cc79212f0 Robert Newson committed Dec 7, 2010
Showing with 7 additions and 2 deletions.
  1. +1 −0
  2. +6 −2 src/main/java/com/github/rnewson/couchdb/lucene/
@@ -379,6 +379,7 @@ The following parameters can be passed for more sophisticated searches;
<dt>analyzer</dt><dd>Override the default analyzer used to parse the q parameter</dd>
<dt>callback</dt><dd>Specify a JSONP callback wrapper. The full JSON result will be prepended with this parameter and also placed with parentheses."</dd>
<dt>debug</dt><dd>Setting this to true disables response caching (the query is executed every time) and indents the JSON response for readability.</dd>
+<dt>default_operator</dt><dd>Change the default operator for boolean queries. Defaults to "OR", other permitted value is "AND".</dd>
<dt>force_json<dt><dd>Usually couchdb-lucene determines the Content-Type of its response based on the presence of the Accept header. If Accept contains "application/json", you get "application/json" in the response, otherwise you get "text/plain;charset=utf8". Some tools, like JSONView for FireFox, do not send the Accept header but do render "application/json" responses if received. Setting force_json=true forces all response to "application/json" regardless of the Accept header.</dd>
<dt>include_docs</dt><dd>whether to include the source docs</dd>
<dt>limit</dt><dd>the maximum number of results to return</dd>
8 src/main/java/com/github/rnewson/couchdb/lucene/
@@ -44,6 +44,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.QueryParser.Operator;
@@ -126,9 +127,10 @@ public void returnSearcher(final IndexSearcher searcher)
- public Query parse(final String query, final Analyzer analyzer) throws ParseException, JSONException {
+ public Query parse(final String query, final Operator operator, final Analyzer analyzer) throws ParseException, JSONException {
final QueryParser parser = new CustomQueryParser(Constants.VERSION,
Constants.DEFAULT_FIELD, analyzer);
+ parser.setDefaultOperator(operator);
return parser.parse(query);
@@ -474,7 +476,9 @@ public void search(final HttpServletRequest req,
for (final String queryString : getQueryStrings(req)) {
final Analyzer analyzer = state.analyzer(req.getParameter("analyzer"));
- final Query q = state.parse(queryString, analyzer);
+ final Operator operator = "and".equalsIgnoreCase(req.getParameter("default_operator"))
+ ? Operator.AND : Operator.OR;
+ final Query q = state.parse(queryString, operator, analyzer);
final JSONObject queryRow = new JSONObject();
queryRow.put("q", q.toString());

0 comments on commit bba040b

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