: 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