Search code examples
c#neo4jcyphershortest-pathneo4j-apoc

A* Neo4j return all paths and conditions on edges


I'm currently using the apoc library to get the shortest path with a cost (length)

apoc.algo.aStar(
    startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 
    'distance','lat','lon'
) YIELD path, weight

There are two things I need:

  1. How would I go about making it return all possible paths and not just the one?

  2. How would I make it only search egdes where PropertyA: true, PropertyB: false, PropertyC contains "abc", etc..?

The answer doesn't have to be using apoc but can be with CYPHER or C# please. Thanks


Solution

  • In answering to your first question you can use allShortestPaths function. For your second question you can set a WHERE CONDITION or your relationship.

    This is my try on my sample database:

    MATCH path=allShortestPaths((:User)-[:MEMBER_OF_GROUP*1..3]-(:Group)) WHERE ALL(x in relationships(path) WHERE x.last_seen > 1534326850) RETURN path
    

    You need add your path in allShortestPaths and for search on edges check path relations in WHERE CONDITION