我是 neo4j 的新手,目前使用带有密码的 Neo4jphp 库来存储和检索节点。我的逻辑相当简单。我想获取一个节点(帖子)并获取它的所有点赞(点赞数)和所有评论(节点)及其评论者(标签用户的节点),并能够解析 php 数组中的 ResultSet 以便稍后将其编码为杰森。
我使用的密码语句是:
MATCH (user:User)-[:POSTED]->(post)
WHERE post.UserID = '13'
AND id(post) = 106
OPTIONAL MATCH ()-[rel:LIKES]-(post)
OPTIONAL MATCH (post)-[:HAS]-(comment:Comment)<-[:COMMENTED]-(commenter:User)
RETURN user, post, count(rel) AS Likes, rel, comment, commenter
匹配正确检索所有节点(虽然这篇文章没有喜欢):
(来源:bookintransit.com)
如何使用库获得该图的正确表示?另请注意,为简单起见,我在此示例中检索了一个帖子节点 (id:106)。但是当我在我的应用程序中使用代码时,我想检索一个帖子列表。
这是我正在使用的 php 代码:
$queryString = "MATCH (user:User)-[:POSTED]->(post) WHERE post.UserID = {qUser} OPTIONAL MATCH ()-[rel:LIKES]-(post) OPTIONAL MATCH (post)-[:HAS]-(comment:Comment)<-[:COMMENTED]-(commenter:User) RETURN user, post,count(rel) AS Likes, rel, comment, commenter ORDER BY post.TS DESC LIMIT ".$NumberOfPosts;
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString, array('qUser' => $UserID));
$result = $query->getResultSet();
if(count($result)>0){
foreach($result AS $row){
// How do I get the correct graph in a php array to parse to json
}