Neo4j PHP以与where相同的顺序返回结果

时间:2015-06-29 12:48:42

标签: php neo4j match where

我有标签“Campaign”的节点。我每次都以不同的顺序得到它们。

因此,在查询数据库后,我有一个包含Campaigns对象的数组。

之后,我将它们发送到db中的另一个函数。

MATCH (campaign:Campaign)
                 where campaign.id="1433855846340" or campaign.id="1433855948013" or campaign.id="1433856017523" or campaign.id="1433856146618" or campaign.id="1433856170282" or campaign.id="1433856364138" or campaign.id="1433856901298" or campaign.id="1433857169469" or campaign.id="1433857216853" or campaign.id="1433873093289" or campaign.id="1433873178949" or campaign.id="1433926766014"
                with campaign optional match campaign<-[:TAKEN_IN]-(picture:Picture) with campaign, collect(picture) as pictures
                with pictures[toInt(rand()*size(pictures))] as picture,campaign
                optional match picture-[:UPLOADED_TO]->(facebookPicture:FacebookPicture)
                RETURN picture.source as coverPicture,campaign.id

基本上我只需要以与where子句相同的顺序返回结果。如果不知道广告系列是否来自数据库,我怎么能这样做呢

  

DESC

,例如/

1 个答案:

答案 0 :(得分:0)

我认为这在您的客户端应用中最容易做,只需在数组中保留id请求并将结果放入键控数组(字典)中,然后通过原始数组中的id检索它们。 / p>

一般情况下,您可以使用cypher中的参数和IN子句替换OR构造。

MATCH (campaign:Campaign)
WHERE campaign.id IN {campaign_ids}
OPTIONAL MATCH campaign<-[:TAKEN_IN]-(picture:Picture) 
WITH campaign, collect(picture) as pictures
WITH pictures[toInt(rand()*size(pictures))] as picture,campaign
OPTIONAL MATCH picture-[:UPLOADED_TO]->(facebookPicture:FacebookPicture)
RETURN picture.source as coverPicture, campaign.id