Thanks a lot for you suggestion!
In my case arrays could consist of up to 40 elements, so option 2). is not really viable. However, 1) - with scripting - might be fine.
However, apart from the solution with using the scripts - which should work
nicely, but will most likely slow down the query considerably in case
when there are many records that match - I have devised another one.
Below I will try to explain its main idea, without code implementation. Any comments are highly appreciated
One considerable condition that I failed to mention (and which might
have given other users valuable hint) is that arrays consist of
enumerated elements, i.e. there are finite number of such elements in
array. This allows to flatten such array into separate field of an
entity.
Lets say there are 5 possible values: 'A', 'B', 'C', 'D', 'E'. Each
of these values is a boolean field - true if it is empty (i.e. array
version would contain this element ) and false otherwise.
Then each of the entities could be rewritten as follows:
1).
A = true
B = true
C = false
D = false
E = false
2).
A = true
B = false
C = true
D = false
E = false
3).
A = true
B = false
C = false
D = false
E = true
4).
A = true
B = false
C = false
D = false
E = false
With the user input of ['A', 'B', 'C'] all I would need to do is:
a) take all possible values (['A', 'B', 'C', 'D', 'E']) and subtract from them user input -> result will be ['D', 'E'];
b) find records where each of resulting elements is false, i.e. 'D = false AND E = false'.
This would give records 1, 2 and 4, as expected. I am still
experimenting with the code implementation of this approach, but so far
it looks quite promising. It has yet to be tested, but I think this
might perform faster, and be less resource demanding, than using scripts
in query.
To optimize this a little bit further, it might be possible not to
provide fields which will be 'false' at all, and modify the previous
query to 'D = not exists AND E = not exists' - result should be the
same.