Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Lucene QueryParser - produce a "portable" query to send to SOLR

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The default operator can be overriden on a per-request basis. For exemple?:

Using params: http://solr/select?q=query&q.op=OR

Or using local params: http://solr/select?q={!lucene q.op=OR}query

See SolrQuerySyntax for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...