neo4j 随机节点输出
neo4j random nodes output
我有一个活动节点与图片节点有关系。
我试图在查询找到的每个广告系列中获取与其关联的随机图片。
我成功地为单个活动获取了一张随机图片,但如果我想为每个活动输出一张关联的图片,我就很难做到。
这是在活动中获取单张照片的示例。
MATCH (campaign:Campaign)-[]-(picture:Picture) where
campaign.id="1429184083571" or campaign.id='1429182615443'
WITH picture, rand() AS r,campaign
ORDER BY r
RETURN campaign,picture
limit 1
我怎样才能为每个活动输出一张连接的随机图片?
这应该有效:
MATCH (campaign:Campaign)-[]-(picture:Picture)
with campaign, collect(picture) as pictures
RETURN campaign,pictures[toInt(rand()*size(pictures))]
我有一个活动节点与图片节点有关系。
我试图在查询找到的每个广告系列中获取与其关联的随机图片。
我成功地为单个活动获取了一张随机图片,但如果我想为每个活动输出一张关联的图片,我就很难做到。
这是在活动中获取单张照片的示例。
MATCH (campaign:Campaign)-[]-(picture:Picture) where
campaign.id="1429184083571" or campaign.id='1429182615443'
WITH picture, rand() AS r,campaign
ORDER BY r
RETURN campaign,picture
limit 1
我怎样才能为每个活动输出一张连接的随机图片?
这应该有效:
MATCH (campaign:Campaign)-[]-(picture:Picture)
with campaign, collect(picture) as pictures
RETURN campaign,pictures[toInt(rand()*size(pictures))]