Reconcile all values ​​in a query for a multi-value field in SOLR

I have a multiValued string in SOLR

named languages ​​and I want the query to return only exact matches where all languages ​​from the query are in the multiValued field.

For example, let's say I have three documents:

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

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

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

      

If I requested English and Russian, I only had to return the first two documents. Here are some examples of queries used:

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

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

d = languages ​​:( "English", "Russian")

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

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

+3


source to share


4 answers


Make sure you write AND

in lowercase. The request will look like this:

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



You can also use +

or -

to cancel part of the request. For example, if you want a document with "English" as the language, but not "Russian", you should use a query like this:

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

+2


source


Try adding &defType=lucene

to the url you are using.



0


source


While this may be a late answer, it would still be a good answer:

First, "and" must be uppercase "AND".
Second, ("terma", "termb") and ("terma" "termb") must be the same. The meaning of "," or "" depends on which default statement you run in schema.xml.
Thirdly, I don't think the result can be a term or a termb if you have specified AND correctly in the search bar.
Fourth, if you really want either ... or ... the result, you can specify languages ​​:( "terma" OR "termb") .

0


source


Above answers are good, but in case you mentioned "AND" or "OR" in stopwords.txt file then solr will remove "AND" and "OR" from your query. We did the same in our project due to the large amount of AND and OR in the data itself.

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

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

0


source







All Articles