neo4j-core icon indicating copy to clipboard operation
neo4j-core copied to clipboard

Multiple matches generate unexpected cypher

Open aekobear opened this issue 6 years ago • 1 comments

When using the Query object to create a query with multiple match statements, the statements are merged into a single match. The resulting cypher produces different results than it would have, had all the matches been preserved.

Given that there are situations where multiple matches are explicitly desired, and given that there is already a notation for writing a multi-pattern match:

q.match('pattern a', 'pattern b')

I think it is most intuitive to have multiple matches retained when the query is converted to cypher.

Additional information which could be helpful if relevent to your issue:

Code example (inline, gist, or repo)

For example, take a graph of a Repo named Test and a chain of dependencies named D1, D2 and D3: image

The query:

q.match('(r:Repo { name: "Test" })-[*]-(d)')
  .match('(d)-[e]-()')
  .return(:d, :e)

generates the cypher:

MATCH (r:Repo { name: "Test" })-[*]-(d), (d)-[e]-() RETURN d, e

which returns only the dependencies D1 and D2.

Forcing multiple matches with a break:

q.match('(r:Repo { name: "Test" })-[*]-(d)')
  .break
  .match('(d)-[e]-()')
  .return(:d, :e)

generates the cypher:

MATCH (r:Repo { name: "Test" })-[*]-(d) MATCH (d)-[e]-() RETURN d, e

which returns all dependencies D1, D2 and D3.

Runtime information:

Neo4j database version: 3.5.0 neo4j gem version: N/A neo4j-core gem version: 9.0.0

aekobear avatar Feb 11 '19 21:02 aekobear

Related to #255

jorroll avatar Feb 11 '19 23:02 jorroll