Solr query to filter document with at least one value in array except of specified values

StackOverflow https://stackoverflow.com/questions/19952103

문제

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>
도움이 되었습니까?

해결책

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" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top