Following on from my earlier question:
Manipulate Lucene query before performing search
I’ve run into a problem where I’m wanting to send a QueryParser parsed Query (Query.toString()) onto a webservice that uses SOLR with a default operator of AND. Because Lucene has OR as its default operator any OR’ed terms are left “as is”. E.g. given the query:
(f1:cat OR f1:dog) AND f2:cow AND f3:"tree frog"
once parsed (with QuerParser.setDefaultOperator(QueryParser.Operator.AND)), the String version becomes:
+(f1:cat f1:dog) +f2:cow +f3:"tree frog"
When this is passed to SOLR, with an assumed AND operator, the two f1 terms get AND’ed instead of OR’ed.
The only work-around I can think of is to change my SOLR installation to use OR as its default Boolean operator… Any other suggestions?
The default operator can be overriden on a per-request basis. For exemple :
Using params:
http://solr/select?q=query&q.op=OROr using local params:
http://solr/select?q={!lucene q.op=OR}querySee SolrQuerySyntax for more details.