2013-08-13 2 views
1

나는 의원에 관한 정보를 담고있는 Neo4j 데이터베이스를 가지고있다. 내가 가지고있는 문제는 빈 자리가 있다면입니다. 이 문제가 발생하면 "의원"색인의 값과 동일한 키를 사용합니다. py2neo 문서에서 내가 코드를 3 번이나 중복 노드가 실행 후 인터페이스를 선택하면 추가 기능이 py2neo create duplicate nodes를 만드는 함수

#Check if we have any vacancies and if so if they match the one that we currently want to add 
    query="start n=node:Congressmen('website:N/A') return n" 
    result= cypher.execute(graph_db, query.encode('utf-8', errors='ignore')) 

    #Match what we already have 
    if str(result[0]) != "[]": 
     #create is idempotent so will only create a new node if properties are different 
     rep, = graph_db.create({"name" : userName, "website" : web, "district" : int(district), "state" : child[2].text, "party" : child[4].text, "office" : child[5].text, "phone" : child[6].text, "house" : "House of Representatives"}) 
     cong = graph_db.get_or_create_index(neo4j.Node, "Congressmen") 

     # add the node to the index 
     cong.add("website", web, rep) 

을 멱등 중임 때문에 나는 아래의 코드를 시도했다. enter image description here

노드가 복제되지 않도록하고 동일한 키/값을 사용하여 색인을 생성 할 수 있습니까?

답변

2

메서드는 확실히 멱등수입니다. 같은 엔티티는 특정 엔트리 포인트에만 한 번만 추가 할 수 있습니다. 그러나 GraphDatabaseService.create 방법은 아닙니다. create 메소드를 실행할 때마다 새 노드가 작성되고 add이 실행될 때마다 새 노드가 색인에 추가됩니다. 대신 Index.add_if_none, Index.create_if_none 또는 Index.get_or_create 메쏘드를 대신 사용하고 싶을 것입니다.