Search code examples
luceneneo4jpy2neo

Add multiple value property to an index with py2neo - Neo4j


I'm trying to store a multiple value property with py2neo in a Neo4j database.

My code is something like this:

names = ["Hello", "Bye"]

batch.add_to_index( neo4j.Node, "NAME", "names", names , mynode )

Sadly, checking resulting Lucene index with lukeall and performing searches, it does not seem to work and it seems everything gets stored as a string like: ["Hello", "Bye"] Would there be any way to properly store it so it can get indexed for all different values?

Thanks in advance!


Solution

  • As it says in the docs, the add_to_index method takes one key and one value as input. So I think you have to add the node to the index twice if you want to index two names.

    # add_to_index(cls, index, key, value, entity)
    
    names = ["Hello", "Bye"]
    
    for n in names:
        batch.add_to_index(neo4j.Node, "NAME", "name", n, mynode)
    
    batch.submit()