Search code examples
pythonneo4jcypherpy2neo

Neo4J: checking if list elements are featured in matched nodes


My Neo4j query is not working - and I can't quite figure out why.

match (entry:Entry)
with split("\some space delimited string", " ") as i, 
split("\some space delimited string", " ") as j

where (any (x in entry.X.list where x in i) and any(y in entry.Y.list 
where y in j) and entry.parent="test_1.csv")
return entry

The properties of an "Entry" node consist of a X, Y and Z parameters.

I am trying, using py2neo, to pass 2 string representations of lists into the cypher query, filter the nodes that contain the intersection of any element of the 2 lists in certain co-ordinate frames (ie. the X of the entry node has an element from list 'i' AND the Y of the entry node has an element from list 'j') - and then return the entry.

However, when I run the query in the Neo4J browser, it tells me that the variable "entry" was not defined.


Solution

  • The WITH clause is used (among other things) to redefine what variables are in scope. Since you didn't include entry in the WITH clause, it dropped out of scope, and so you can't use it past that point, thus the error.

    To fix this, simply add entry in that WITH clause along with i and j:

    ...
    with entry, split("\some space delimited string", " ") as i, 
    split("\some space delimited string", " ") as j
    ...