2015-11-06 40 views
1

我对neo4j相当陌生,并且构造了db它由> 10M节点组成。在查询操作期间,我想通过使用两个properties来查找节点。例如:节点 - name: xxx surname: yyy id:1在查询操作期间我需要获得节点id其中name: xxx, surname: yyy。 java查询(不是cypher)怎么可能?并且会有多个具有给定属性的条目。如何读取neo4j中节点的属性?

回答

1

这里是如何找到IDS为例:

GraphDatabaseService database; 

Label label = DynamicLabel.label("your_label_name"); 
String propertyId = "id"; 
String propertyName = "name"; 
String propertySurname = "surname"; 

public Set<Node> getIdsForPeople(Set<Person> people) { 

    Set<String> ids = new HashSet<>(); 

    try(Transaction tx = database.beginTx()) { 
     for (Person person in people) { 
      Node node = database.findNode(label, propertyName, person.getName()); 

      if (node.hasProperty(propertySurname)) { 
       if (node.getProperty(propertySurname) == person.getSurname()) { 
        String id = node.getProperty(propertyId).toString(); 

        ids.add(id); 
       } 
      } 
     } 

     tx.success(); 
    } 

    return ids; 
} 

人座

public class Person { 

    private final String name; 
    private final String surname; 

    public Person(String name, String surname) { 
     this.name = name; 
     this.surname = surname; 
    } 

    public String getName() { return name; } 
    public String getSurname() { return surname; } 
} 

例如

Set<Person> people = new HashSet<Person>(){{ 
    add(new Person("xxx1", "yyy1")); 
    add(new Person("xxx2", "yyy2")); 
    add(new Person("xxx3", "yyy3"); 
    add(new Person("xxx4", "yyy4"); 
}}; 

Set<String> ids = getIdsForPeople(people); 
+0

如果有多个条目与给定的规范怎么办? –

+0

@RaufAgayev更新 – MicTech

相关问题