Cypher在py2neo中查询

时间:2014-10-16 00:55:05

标签: neo4j py2neo

我开始使用py2neo并尝试处理一些示例数据集。这是(简化的)原始查询集:

CREATE (Ann:person{name:'Ann',gender:'female'})
CREATE (Target:store{name:'Target',location:'New York'})
CREATE (Ann)-[:PURCHASED {amount:'100',status:'denied'}]->(Target)

在py2neo中我尝试了这个:

ann,=graph_db.create(node({name:'Ann',gender:'female'}))
ann.add_labels("person")

target,=graph_db.create(node({name:'Target',location:'New York'}))
target.add_labels("merchant")

(ann,"PURCHASED",target,{'amount':'100', 'status':'denied'})

此查询返回

(Node('http://localhost:7474/db/data/node/0'),
 'PURCHASED',
 Node('http://localhost:7474/db/data/node/3'),
 {'amount': '100', 'status': 'denied'})

我有很多不同的用户,所以我想找到所有被拒绝交易的人

query_string="""
MATCH (customer:person)-[r:PURCHASED]->(merchant)
WHERE r.status = "denied"
RETURN customer.name as customer_name
"""

然后我尝试执行它

result = neo4j.CypherQuery(graph_db, query_string).execute()

它返回一个空对象。我做错了什么?

1 个答案:

答案 0 :(得分:0)

我建议,在创建节点或关系时,分别使用merge_one和create_unique,以确保您不会创建任何重复项。

E.g:

class Program
{
    static void Main(string[] args)
    {
        Shape[] areaOfShapes = new Shape[3];

        areaOfShapes[0] = new Point(10, 5);
        areaOfShapes[1] = new Circle(20);
        areaOfShapes[2] = new Cylinder(25,12);

        foreach(Shape item in areaOfShapes)
        {
            Console.WriteLine(item);
        }
        Console.ReadLine();
    }
}