I will explain steps:
-
WITH post, rule, collect(DISTINCT category.name) AS categories
will return:
post1, rule1, ['PARENT']
post1, rule2, ['SCHOOL']
post1, rule3, ['TOPICS']
post1, rule4, ['GRADE1', 'GRADE3'] -
WITH post, collect(categories) AS rule_cats
will return:
post1, [['PARENT'], ['SCHOOL'], ['TOPICS'], ['GRADE1', 'GRADE3']] -
WHERE all(x IN rule_cats WHERE any(n IN x WHERE n IN $allowedCategories))
will check for each element of rule_cats if at least one of the category is in $allowedCategories
I hope it's more clear now