If the number of properties is greater than n, return a subgraph in Neo4j

后端 未结 1 565
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 14:52

This question is a direct extension of a question I asked previously.

Say I have a graph database that looks like this:

Just like the previous question

1条回答
  •  盖世英雄少女心
    2021-01-26 15:38

    This query will filter out all sub-paths from the results:

    MATCH p=(a:person)-[:RELATED_TO*]->(b:person)
    WHERE
      NOT ()-[:RELATED_TO]->(a) AND
      NOT (b)-[:RELATED_TO]->() AND
      2 < REDUCE(s = 0, x IN NODES(p) | CASE WHEN x. SomeProperty = 'Yes' THEN s + 1 ELSE s END)
    RETURN p;
    

    Explanation:

    • NOT ()-[:RELATED_TO]->(a) is true if the a node is not the at the end of a RELATED_TO relationship.
    • NOT (b)-[:RELATED_TO]->() is true if the b node is not at the start of a RELATED_TO relationship.

    Therefore, a matching path cannot be a sub-path.

    0 讨论(0)
提交回复
热议问题