Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene query for array and "IN", "ALL IN", "ANY IN" operations

Tags:

lucene

I need to implement the following predicate with Lucene query language:

{param} IN optionIds

where {param} is my external parameter and optionIds is an array(or collection).

for example I have the document with the following optionIds:

"optionIds": [
    72,
    44,
    11,
    9,
    10
  ]

The following Lucene predicate optionIds:72 correctly returns this document.

But how to return this document based on the follownig values: 72, 11, 9

The following predicate optionIds:72, 11, 9 doesn't work and the Lucene query returns the empty result.

Please show how to properly use(emulate) IN operation in Lucene query language with arrays(collections). Also, please show how to use ALL IN/ANY IN.

like image 897
alexanoid Avatar asked May 22 '18 17:05

alexanoid


1 Answers

To match any of the query terms to list in the document:

optionIds:(72 11 9)

To match all of the query terms:

optionIds:(+72 +11 +9)
like image 144
femtoRgon Avatar answered Oct 26 '22 06:10

femtoRgon