Pregunta

I have a dataset containing words and documents associated with those words. I would like to set labels on them to separate them into these two categories. I was able to create the labels by doing this:

if not "Social Words" in graph_db.node_labels:
    neo4j.Schema.create_index(graph_db.schema, "Social Words", "word")

if not "Documents" in graph_db.node_labels:
    neo4j.Schema.create_index(graph_db.schema, "Documents", "url")

The problem is that I need to enforce uniqueness on the "word" and "url" fields. I am adding the nodes & labels as follows

doc,= graph_db.create({"url": url})
doc.add_labels("Documents")

My questions are :

  1. Is there a way to add the node to the label index by using get_or_create
  2. Does the py2neo api have a way to enforce uniqueness on the label index
  3. Is there a better way to do all this. The documentation is a little fuzzy
¿Fue útil?

Solución

Answers:

  1. No because there is no need to explicitly add a node to a schema index - these are included automatically when the label is present.
  2. Py2neo does not have specific functions to support unique constraint management.
  3. You could use Cypher for this instead (http://docs.neo4j.org/chunked/stable/query-constraints.html#constraints-create-uniqueness-constraint)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top