我很难从两个不同的来源收集数据并合并集合,以便最后一个是由'dateCreated'排序的一组对象。
上下文
用户可以分组提问。 问题可以是一般性的,也可以与特定的视频游戏相关。 如果小组中提出的问题与视频游戏相关,则此问题也会出现在视频游戏的问题页面中。
目前,我有两个一般性问题,一个特定于一个视频游戏。 因此,在提问时,我应该有3个问题。
查询
以下是查询:
START group = node(627)
MATCH generalQuestions-[?:GENERAL_QUESTION]->group
WITH group, generalQuestions
MATCH gamesQuestions-[?:GAME_QUESTION]->games<-[:GAMES]-group
WITH (collect(generalQuestions) + collect(gamesQuestions)) as questions
RETURN questions
ORDER BY questions.dateCreated
第一期:使用ORDER BY
Cached(questions of type Collection) expected to be of type Map but it is of type Collection - maybe aggregation removed it?
实现我想要做的事情的正确方法是什么?
第二个问题:结果错误
如果我删除了ORDER BY子句,而不是有3个结果,我得到14 ......:
[
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[641]{dateCreated:1380892636,dateUpdated:1380892636,title:"GENERAL TITLE 1",type:1,content:"GENERAL CONTENT 1"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[642]{dateCreated:1380892642,dateUpdated:1380892642,title:"GENERAL TITLE 2",type:1,content:"GENERAL CONTENT 2"},
Node[632]{dateCreated:1380889484,dateUpdated:1380889484,title:"GTA5 TITLE",type:2,content:"GTA5 CONTENT"},
Node[632]{dateCreated:1380889484,dateUpdated:1380889484,title:"GTA5 TITLE",type:2,content:"GTA5 CONTENT"}
]
我收集结果的方式有问题吗?
修改
扩展查询以获取gamesQuestion:
gamesQuestions-[:GAME_QUESTION]->()<-[:QUESTIONS]-games-[:INTERESTS]->()<-[:HAS_INTEREST_FOR]-interests<-[:INTERESTS]-group
感谢您的帮助,
答案 0 :(得分:3)
“Order by”需要节点或关系上的属性。查询中的“问题”是节点的集合而不是节点/关系,您无法使用“排序依据”对集合进行排序,您只能对其属性上的节点或关系进行排序。
为了使用“Order by”,您需要将问题作为一列而不是一个集合返回。根据原始查询中指示的关系,以下查询应将常规和特定游戏问题作为行列返回,并在属性“dateCreated”上对其进行排序,
START group = node(627)
Match question-[?:GENERAL_QUESTION|GAME_QUESTION]->()<-[:GAMES*0..1]-(group)
Return distinct question
Order by question.dateCreated
对于游戏问题通过关系序列“游戏问题 - [?: GAME_QUESTION] - &gt;游戏&lt; - [:GAMES] -group与群组相关的扩展案例,我有游戏问题 - [:GAME_QUESTION] - &gt;()&lt; - [:QUESTIONS] -games - [:INTERESTS] - &gt;()&lt; - [:HAS_ INTEREST_FOR] -interests&lt; - [:INTERESTS] -group“,你可以简单地扩展上一个查询中的模式如下,
START group = node(627)
Match question-[:GENERAL_QUESTION|GAME_QUESTION]->()-[*0..4]-(group)
Return distinct question
Order by question.dateCreated
我们的想法是将可以到达组节点的问题与一步或四步相匹配。
另一种选择是在where子句中指定两种模式,
START group = node(627)
MATCH question-[*]-group
Where question-[:GENERAL_QUESTION]->group or (question-[:GAME_QUESTION]->()<-[:QUESTIONS]-()-[:INTERESTS]->()<-[:HAS_INTERESTS_FOR]-()<-[:INTERESTS]-group)
Return distinct q
Order by q.dateCreated