The scenario is this: I have an ArangoDB collection containing items, and another collection containing tags. I am using a graph, and I have an edge collection called "Contains" connecting the items and tags. An item has multiple tags.
Now I am trying to do a search for items containing multiple tags. E.g. items containing the tags "photography", "portrait" and "faces".
My general approach is to start a graph traversal from each of the tag vertices and find the items that relate to that tag. That part works fine. I get a list of items.
But the last part of my task is to make an intersection of all the lists in order to find the items that contain ALL the tags specified. And I cannot work out how to do this.
What I wanted to do was something like this:
let tagnames = SPLIT(@tagnames,',')
let tagcollections = (
FOR tagname IN tagnames
LET atag = (FOR t IN tags FILTER LOWER(t.text)==LOWER(tagname) RETURN t)
let collections = (FOR v IN 1..1 INBOUND atag[0] Contains RETURN v)
RETURN { tag: atag, collections: collections }
)
RETURN INTERSECTION(tagcollections)
However, it doesn't work: The INTERSECTION function does not work on a single list, but on multiple items, like this: INTERSECTION(listA, listB, listC...).
How can I make an intersection of the lists found in the FOR .. RETURN block?
APPLY("INTERSECTION", [listA, listB, listC])
. It is identical toINTERSECTION(listA, listB, listC)
, but the input array can have variable length. – Tarweed