You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Omri Cohen <om...@gmail.com> on 2011/09/14 15:49:50 UTC

query - part default OR and part default AND

Hi All,

I have two fields in my schema: field1, field2 , for the sake of the example
I'll define to phrases:
phrase1 - solr is the best fts ever
phrase2 - let us all contribute to open source for a better world

now I want to perform the next query:

field1:( phrase1) AND field2:(phrase2)

my default operator is AND, but I want to search within field1 with AND
operator between the tokens and within field2 with OR operator.
what i already tried is to split phrase1 by whitespaces, changing the
default search operator to OR in the schema and add + signs before each
word:

field1:(+solr +is +the +best +fts +ever) AND field2:(let us all contribute
to open source for a better world)

this query is not good.. because when I am splitting phrase1 it is not how
the index time tokenizer splits it... so I am not getting the results I
would like to...

any idea any one?

Thanks,

Omri

Re: query - part default OR and part default AND

Posted by Chris Hostetter <ho...@fucit.org>.
: phrase1 - solr is the best fts ever
: phrase2 - let us all contribute to open source for a better world
: 
: now I want to perform the next query:
: 
: field1:( phrase1) AND field2:(phrase2)
: 
: my default operator is AND, but I want to search within field1 with AND
: operator between the tokens and within field2 with OR operator.
	...
: field1:(+solr +is +the +best +fts +ever) AND field2:(let us all contribute
: to open source for a better world)

First off -- be careful about your wording.  you are calling these 
"phrases" but in these examples, what you are really doing is searching 
for a set of terms.  there's no such thing as an "OR" phrase search -- 
when searching for phrases the entire phrase is mandatory, your only 
option is if you want to include any "slop" in how far apart the 
individual terms may be.

having said that: if what you want to do is search "all" of a set of 
terms in field1, and "any" of a set of terms in field2, you can use 
localparams and the _query_ hook in the LucneeQParser to split this up 
into multiple params where you specify a diffenret default op...

q=_query_:"{!q.op=AND df=field1 v=$f1}" _query_:"{!q.op=OR df=field2 v=$f2}"
f1=solr is the best fts ever
f2=let us all contribute to open source for a better world

: what i already tried is to split phrase1 by whitespaces, changing the
: default search operator to OR in the schema and add + signs before each
: word:
	...
: this query is not good.. because when I am splitting phrase1 it is not how
: the index time tokenizer splits it... so I am not getting the results I

Second: this is't how the Lucene QueryParser works: whitepsace is a 
metacharacter for the queryparser, it splits on (unescaped) whitespace to 
determine individual clauses (which are then used to build boolean 
queries) before it ever consults the analyzer for the specified field (it 
actually doesn't even know which field it should use until it evaluates 
the whitespace it's parsing)

Reading between the lines, i *think* what you are saying is that you wnat 
to search for an exact phrase on field1, but any of hte words in field2, 
which is as simple as...

field1:"solr is the best fts ever" AND field2:(let us all contribute to open source for a better world)

...of course, if it's easier for your client to specify those as distinct 
params, you can still use the _query_ hook and local params, along with 
the "field" QParser..

q=_query_:"{!field f=field1 v=$f1}" _query_:"{!q.op=OR df=field2 v=$f2}"
f1=solr is the best fts ever
f2=let us all contribute to open source for a better world

...Lots of options.

https://wiki.apache.org/solr/SolrQuerySyntax



-Hoss

Re: query - part default OR and part default AND

Posted by "tamanjit.bindra@yahoo.co.in" <ta...@yahoo.co.in>.
Keep the default Search Operator as OR
And for phrase1, on splitting on whitespace just add "AND" instead of "+".

Hopefully this should work. Please do confirm.

--
View this message in context: http://lucene.472066.n3.nabble.com/query-part-default-OR-and-part-default-AND-tp3335851p3336194.html
Sent from the Solr - User mailing list archive at Nabble.com.