4

I have a string multiValued field in SOLR named languages and I want a query to return only exact matches where all of the languages from the query are in the multiValued field.

For example, lets say I have three documents:

 "languages": [
          "English",
          "Russian",
          "Swedish"
        ],

"languages": [
          "English",
          "Japanese",
          "Russian",
          "Spanish",
          "Thai"
        ],

"languages": [
          "English",
          "Spanish"
        ],

If I were to query for English and Russian I should only return the first two documents. Here are some examples of the queries used:

q=languages:"English" and languages:"Russian"

q=languages:("English" and "Russian")

q=languages:("English","Russian")

q=languages:("Russian" "English")

In all cases these return all records that have either English or Russian. I may be overlooking something obvious but I have searched around and found nothing that explains this behavior.

Dyrandz Famador
  • 4,499
  • 5
  • 25
  • 40
user4372823
  • 43
  • 1
  • 3
  • How is your default requesthandler configured? You will find it within your solrconfig.xml. The tag is named `` with `default=true`. – cheffe Dec 18 '14 at 09:01

4 Answers4

2

Make sure you write the AND in upper case letters. The query would look like this:

q=languages:"English" AND languages:"Russian"

You can also use + or - to negate a part of the query. For example if you want a document which has "English" as a language but not "Russian", you would use a query like this:

q=+languages:"English" AND -languages:"Russian"

user2894821
  • 186
  • 4
0

Please try to add &defType=lucene to URL which you use.

Paweł Róg
  • 126
  • 1
  • 2
0

Though this might be a late answer, it'd still be good late answer:

Firstly, "and" must be uppercase "AND".
Secondly, ("terma", "termb") and ("terma" "termb") should be same thing. The meaning of "," or " " depends on what the default operator you sepcify in schema.xml.
Thirdly, I don't think it's possible that the result is either terma or termb if you did specify AND correctly in search string.
Fourthly, if you really want either...or... result, you can specify like this: languages:("terma" OR "termb").

Scott Chu
  • 972
  • 14
  • 26
0

Above answers are good but in case you have mentioned "AND" or "OR" in your stopwords.txt file then solr will remove "AND" and "OR" from your query. We have done same thing in our project due to lots of AND and OR in data itself.

In this case you can use && (for AND) and || (for OR) as conditional parameters in your query.

Example: q=languages:"English" && "Russian"

Naresh Joshi
  • 4,188
  • 35
  • 45