使用neography按属性值过滤

时间:2012-04-12 06:19:28

标签: neo4j neography

我正在测试一个工作neography示例的简单变体,虽然过滤器看起来好像应该有效,但我没有运气。我可以过滤position.length并且它工作正常,但我现在正在尝试根据节点属性进行过滤。

鉴于这些节点:

node1 = Neography::Node.create("name" => "node1")
node2 = Neography::Node.create("name" => "node2")
person1 = Neography::Node.create("name" => "Person1", "role" => "author")
person2 = Neography::Node.create("name" => "Person2", "role" => "author")
person3 = Neography::Node.create("name" => "Person3", "role" => "editor")
Neography::Relationship.create(:user, node1, person1)
Neography::Relationship.create(:user, node2, person2)
Neography::Relationship.create(:user, node1, person3)
Neography::Relationship.create(:user, node2, person3)

将“the_node”设置为person1,我试图让它返回person3:

the_node.both(:user).
    order("breadth first").
    uniqueness("node global").
    #filter("position.length() == 2;").
    filter("currentNode.getProperty('role') == 'editor';").
    depth(2).
    map{|n| n.name}.join(', ')

注释掉的过滤器按预期返回person3(第二级关系),但基于'role'属性的过滤器似乎过滤了所有内容,因此结果为空。

任何建议都会很棒;我是neo4j和neography的新手。

1 个答案:

答案 0 :(得分:0)

而不是遍历端点,我会查看密码,请参阅Neography支持的http://docs.neo4j.org/chunked/snapshot/cypher-query-lang.html

您的查询将类似

start user = node(1) 
match user-[:user]->person 
where person.role = "editor" 
return person.name

HTH