Question

Is there a way to filter query, so I will get documents with specific array filed containing at least one other value except of values which I pass.

For example I have 3 docs.

<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 want documents which contains at least one other value in my_array except of 2 and 4. So result will be:

<doc>
  <arr name="my_array">
    <int>4</int>
    <int>3</int>
    <int>1</int>
  </arr>
</doc>
Was it helpful?

Solution

You can try

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

This translates to

  1. my_array shall contain 2 or 4
  2. my_array shall contain a value x, with x < 2, x between 3 and 3, x > 4

I know that the between 3 and 3 is a bit strange, but that is due to the example.

The caveat of this is that you need to calculate the query on the client side to get the range clauses right. Although the logic to compute this is not too hard.


I have tried this with eDisMax, which is configured like this

<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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top