Using path or split to nodes by label

Hi,

I need to find a path between 2 persons and i need all nodes and relationships between them...
I have 2 labels: 'Company', 'Factory'. A person can have many relationships to companies and factories.
I wrote a query that gives me all data but i can't load it to neo4j.netclient.
The start and end nodes work but the PathsResult doesn't.
I thought it would be a good idea to split the nodes in the path by labels so i can get 2 arrays of nodes and array of relationships.
How can i achieve that?

Here is the code in cypher:
MATCH (nstart:Person) WHERE nstart.idNumber = '1234'
WITH nstart
MATCH (nend:Person) WHERE nend.idNumber = '5678'
MATCH path = shortestPath((nstart)-[*..10]-(nend))

RETURN nstart, nend, path

Here is the code in c#:
...Return((nstart, path, nend) => new
{
start = nstart.As<>(),
paths = path.As<IEnumerable>(),
end = nend.As<>()
}).Limit(100);

The path itself is not a collection. You can get the list of nodes from a path variable with the ‘nodes’ function and the relationships with the ‘relationships’ function.

You can either apply the functions in your return statement so you return them as columns. These will be collections.

The alternative is to extract the path in your C# code as a Path type and then get the nodes and relationships in your code.

Hi, Thanks,
In the path i have 3 types of nodes "Person", "Company", "Factory" and i want to return a collection of each type, and a collection of relationships, so i can serialize every collection in c# array.
BTW, I tried using PathsResult and i contains empty elements

Ty this:

MATCH (nstart:Person) WHERE nstart.idNumber = '1234'
MATCH (nend:Person) WHERE nend.idNumber = '5678'
MATCH path = shortestPath((nstart)-[*..10]-(nend))

RETURN nstart, nend, 
[n in nodes(path) where n:Person] as PersonNodes,
[n in nodes(path) where n:Company] as CompanyNodes,
[n in nodes(path) where n:Factory] as FactoryNodes,
relationships(path) as relationships

I am not familiar with PathsResult.

Thanks Gary,

It works great!

1 Like