我有这样的查询
START a = node:lucene_index('name: "actor1"')
MATCH (a:Actor)--(b:Movies)
WHERE b.director = 'director1'
WITH b LIMIT 4
RETURN 'Movies' AS resultType, collect (DISTINCT b) as resultList
UNION ALL
START a = node:lucene_index('name: "actor1"')
MATCH (a:Actor)--(b:Movies)
WHERE b.director = 'director2'
WITH b LIMIT 4
RETURN 'Movies' AS resultType, collect (DISTINCT b) as resultList
UNION ALL
START a = node:lucene_index('name: "actor1"')
MATCH (a:Actor)-[r]-(b:Movies)
WITH b
MATCH (b)-[r2]-(b2:Actor)
WITH b, count(r2) as relations
ORDER BY toInt(relations) DESC
LIMIT 2
RETURN 'Movies' AS resultType, collect (DISTINCT b) as resultList
是否可以将这些查询合并为一个? 重要的是,resultList按照查询
中所示的顺序包含电影谢谢!
答案 0 :(得分:0)
您可能需要查看post-union processing上的Neo4j知识库文章。这提供了一些方法来执行您的工会,但之后能够执行排序操作。
当然,你需要一些东西来解决这个问题。我会为每个(例如order
)添加第三个字段,并为第一个子查询显式设置为1,第二个子查询显式设置为2,第三个子查询显式设置为3。然后在联合后处理时对该字段进行排序。