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 vsriram30 <vs...@gmail.com> on 2014/10/30 18:17:53 UTC

Solr And query

Hi All,

This might be a simple question. I tried to find a solution, but not exactly
finding what I want. I have the following fields f1, f2 and f3. I want to do
an AND query in these fields. 

If I want to search for single word in these 3 fields, then I am facing no
problem. I can simply construct query like, q=f1:word1 AND f2:word2 AND
f3:word3 . But if I want to search for more than one word, then I am
required to enclose it in double quotes. eg) q=f1:"word1 word2" AND f2:word3
AND f3:word4 But the problem I am facing with this approach is, word1 and
word2 has to appear in the same order in field f1.But for my use case, I
don't require it. It can be present anywhere in that field and I want same
scoring irrespective of where it is present. In simpler words, I just want
basic term matching of those words in that field.

Hence I tried the following solutions,

1. Using a slop query:

I constructed query like q=f1:"word1 word2"~1000 AND f2:word3 AND f3:word4
I read that it puts more load on CPU as it finds the position difference
between those words and creates the score. I just want a plain term matching
and I don't require score to vary based on distance.

2. Using Filter query:

I constructed query like, q=word1 word2&df=f1&fq=f2:word3&f3:word4 The score
is way less as it is not using filter query terms for scoring. Also since I
enabled filter cache, I don't want these filter queries to be cached. Hence
I don't want to use filter queries for these fields.

3. Using AND operator and df:

I constructed query like, q=word1 word2 AND f2:word3 AND f3:word4&df=f1.
This works perfectly fine as word1 and word2 are searched in f1 and other
AND queries are also working fine. But now, If I want to search for 2 words
in f2 as well, then I am not sure how to construct query.

eg) q=word1 word2 AND f2:word3 word4 AND f3:word5 word6&df=f1 .Here, word4
and word6 will be searched against field f1. But I want them to searched on
f2 and f3 respectively. Hence please help me with this.

Thanks,
Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr And query

Posted by vsriram30 <vs...@gmail.com>.
Yes Erick. Correctly pointed.

Thanks,
Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685p4166789.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr And query

Posted by Erick Erickson <er...@gmail.com>.
Ummmm. That may be true for your particular example data set, but not
in the general case, so don't be fooled.

q.op=AND is equivalent to
q=f1:(word1 AND word2) AND f2:(word3 AND word4) AND f3:(word5 AND word6)

This query
q=f1:"word1 word2" AND f2:"word3 word4" AND f3:"word5 word6"
would not match a document like this

f1:word2 word1
f2:word3 word4
f3:word5 word6

since it requires that the words be in order. Whereas

q=f1:(word1 AND word2) AND f2:(word3 AND word4) AND f3:(word5 AND word6)

would match the doc.

Best,
Erick


On Thu, Oct 30, 2014 at 5:46 PM, vsriram30 <vs...@gmail.com> wrote:
> Thanks Eric. I tried q.op=AND and noticed that it is equivalent to
> specifying,
> q=f1:"word1 word2" AND f2:"word3 word4" AND f3:"word5 word6"
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685p4166760.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr And query

Posted by vsriram30 <vs...@gmail.com>.
Thanks Eric. I tried q.op=AND and noticed that it is equivalent to
specifying,
q=f1:"word1 word2" AND f2:"word3 word4" AND f3:"word5 word6"



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685p4166760.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr And query

Posted by Erick Erickson <er...@gmail.com>.
Right, but do be aware of one thing. The form
f1:(word1 word2) has an implicit OR between them
based on "q.op" which is specified in your
solrconfig.xml file for the request handler you're
using.

This is no problem, but if you ever specify "q.op" as AND
either in solrconfig.xml or as an explicit parameter to the
search you'll get a different logical expression.

Best,
Erick

On Thu, Oct 30, 2014 at 3:45 PM, vsriram30 <vs...@gmail.com> wrote:
> Actually I found out how to form the query. I just need to use,
>
> q=f1:(word1 word2) AND f2:(word3 word4) AND f3:(word5 word6)
>
> Thanks,
> V.Sriram
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685p4166744.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr And query

Posted by vsriram30 <vs...@gmail.com>.
Actually I found out how to form the query. I just need to use,

q=f1:(word1 word2) AND f2:(word3 word4) AND f3:(word5 word6)

Thanks,
V.Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-And-query-tp4166685p4166744.html
Sent from the Solr - User mailing list archive at Nabble.com.