Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr AND operator

Tags:

solr

I have a problem getting the right results with my SOLR query. Basically, let's say I want all documents in English containing the string "toto".

http://127.0.0.1:8080/solr-webservice/query/?q=iso_lang_cd:en&ctnt_val:*toto*

The problem is that this query sends me all documents in English AND all documents containing toto.

What I need is to get all documents that are in English AND contain toto. How could I achieve this? I'd think this is the standard use of the AND operator...

like image 774
Lupuss Avatar asked Jul 18 '26 16:07

Lupuss


1 Answers

Actually OR is the default query operator for Solr and your query is not formatted in such a away as to force an AND operation. In order to achieve the AND behavior you could specify your query in one of the following formats:

 +iso_lang_cd:en +ctnt_val:*toto*

 iso_lang_cd:en && ctnt_val:*toto*

Or you can optionally pass the q.op=AND to force an AND operation. Additionally, you might want to consider using Filter Queries, where you could filter on the language. There are some performance improvements with using filter queries, but please refer to the documentation for more details.

 q=ctnt_val:*toto*&qf=iso_lang_cd:en

Please see The Standard Query Parser for more details and a good overview of querying.

like image 83
Paige Cook Avatar answered Jul 23 '26 22:07

Paige Cook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!