neo4jnosqlgraph-databasesconnected-components

How to filter components in according to nodes values in Neo4j


I created my network in Neo4j, in particular, it's composed of many "chains" ( every node can have at most one incoming edge and at most one outgoing edge). How can I make a query in order to return all those chains composed by only nodes having a value in range <x,y>? (you can consider every node has Identifier|date|value)

example: >7
3-->10-->9-->4 IGNORED
8-->10-->9-->12 TAKEN

ps: I tried to use libraries such as gds, and it seems very helpful, but still I can't figure out.

Thank you


Solution

  • I would try the following:

    MATCH p= (n)-[*]->(m)
    WHERE NOT (n)<--() AND NOT (m)-->()
    WITH p
    WHERE all(node in nodes(p) WHERE x < node.value y)
    RETURN p
    

    First, you filter all the paths from start to end and then apply the range filter on all nodes in the path.

    Edit: based on comment, to consider also chains composed of one node you can do:

    MATCH p= (n)-[*0..]->(m)
    WHERE NOT (n)<--() AND NOT (m)-->()
    WITH p
    WHERE all(node in nodes(p) WHERE x < node.value y)
    RETURN p