检查list1是否包含neo2j中list2顺序相同的list2中的所有项目?

时间:2018-06-25 10:28:39

标签: neo4j cypher

例如,我在数组下面

Array1 = ["d","c","b"]
Array2= ["d","c","x"]
Array3= ["a","C"]
Array4= ["a","d","c","b","x"]

我想将Array1,2,3与Array4进行比较,结果应该是Array1,因为in中包含d,c,b,在Array4中排列正确。

1 个答案:

答案 0 :(得分:0)

最简单的方法是将数组转换为字符串,然后执行CONTAINS where子句:

这是一个示例:

WITH ["d","c","b"] AS test, ["a","d","c","b","x"] AS array
WITH test, reduce(v='|', x in test | v + x + '|') as testAsString, reduce(v='|', x in array | v + x + '|') as arrayAsString
 WHERE arrayAsString CONTAINS testAsString
 RETURN test

请注意,如果在数组值中有|,则此代码可能会给您带来一些误报。