Solr query to filter a document with at least one value in the array, except for the specified values

Is there a way to filter the request, so I get documents with a specific array containing at least one other value, except for the values ​​that I pass.

For example, I have 3 documents.

<doc> <arr name="my_array"> <int>2</int> <int>4</int> </arr> </doc> <doc> <arr name="my_array"> <int>2</int> </arr> </doc> <doc> <arr name="my_array"> <int>4</int> <int>3</int> <int>1</int> </arr> </doc> 

I need documents that contain at least one value in my_array , with the exception of 2 and 4. Thus, the result will be:

 <doc> <arr name="my_array"> <int>4</int> <int>3</int> <int>1</int> </arr> </doc> 
+6
source share
1 answer

You can try

 qf=my_array&q=+(2 4) +([* TO 1] [3 TO 3] [5 TO *]) 

It means

  • my_array should contain 2 or 4
  • my_array should contain the value x, where x <2, x between 3 and 3, x> 4

I know that between 3 and 3 little strange, but this is due to an example.

The caveat is that you need to calculate the client-side request in order to get the range offers correctly. Although the logic for calculating this is not too complicated.


I tried this with eDisMax , which is configured as follows

 <requestHandler name="standard" class="solr.StandardRequestHandler"> <lst name="defaults"> <str name="defType">edismax</str> <str name="fl">*,score</str> <str name="mm">1</str> </lst> </requestHandler> <queryParser name="edismax" class="org.apache.solr.search.ExtendedDismaxQParserPlugin" /> 
+4
source

Source: https://habr.com/ru/post/957982/


All Articles