Search code examples
propertiesfilterneo4jneo4j-embedded

Neo4j embedded: filter on node properties using graph algorithm


I am using Neo4j embedded from eclipse and want to navigate through a network of trips and stations. They are connected the following way:

(t:Trip)-[:STOPS {arrival:"10:12:00", departure:"10:13:00"}]->(s:Station)

As a trip has several stops and there are several trips which stop at one station there are many connections. Sometimes it is not possible to get from one station to another without changing to a different trip. For that reason I use the following graph algo

    PathFinder<Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.forType(RelTypes.STOPS), depth);
    ArrayList<Path> path = (ArrayList<Path>) finder.findAllPaths(source,target);

But I can't find if there are ways to filter on my properties arrival and departure because I want to find only trips which depart after a given time.


Solution

  • Instead of PathExpanders.forType() you need to use your custom implementation of PathExpander.

    Your implementation would basically filter path.endNode().getRelationships(RelTypes.STOPS) for those having correct arrival and departure properties.