Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow default_operator=and. Closes #95

  • Loading branch information...
commit 9efa7993127acf82f621c17a38d6420675f3b1ec 1 parent 6f81165
@rnewson authored
View
1  README.md
@@ -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>
View
8 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
@@ -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;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -126,9 +127,10 @@ public void returnSearcher(final IndexSearcher searcher)
returnReader(searcher.getIndexReader());
}
- 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());
Please sign in to comment.
Something went wrong with that request. Please try again.