can you put a _join: "OR" in a term?
paolomaffei opened this issue · 3 comments
I have a set of conditions that needs to be matched each with AND but together need to evaluated as OR
example: (does this vessel come from either "italy" OR "england") AND (goes to either "italy" OR "norway") ?
is this possible at all?
Sure, it should be. I have done it many times in the projects that led to the generation of searchjs (and am pretty sure it made it in, but will check). So you should be able to do:
// first from italy or from england
{_join:"OR",terms:[{from:"italy"},{from:"england"}]}
// next to italy or to norway
{_join:"OR",terms:[{to:"italy"},{to:"norway"}]}
// putting it together
{_join:"AND",terms:[
{_join:"OR",terms:[{from:"italy"},{from:"england"}]},
{_join:"OR",terms:[{to:"italy"},{to:"norway"}]}
]}
You can simplify it further with arrays:
{_join:"AND",terms:[
{from:["italy","england"]},
{to:["italy","norway"]}
]}
Which means you can simplify it even further as:
{from:["italy","england"], to:["italy","norway"]}
The simplification only works because you gave a case that works with it, but it should work. Let's run a test.
hi thanks for your answer - indeed my example was simplified from my actual needs
Pleasure. Use it well!