Search code examples
orientdb

'Match' on OrientDB returns a path that doesn't exist


I am using OrientDB 'match' to get a path (on the graph) according to a criteria, but I get a result path that doesn't exist.

I have a "Person" vertex that has a "PhoneCall" edge to another "Person" vertex - only one path should be a match! so I expext to get as a result: vertex1-edgeX-vertex2 For example - "jonn Smith --phoneCallX-- dan smith"

What I actually get is 2 pathes:

  1. vertex1-edgeX-vertex2 (jonn Smith --phoneCallX-- dan smith) but also:
  2. vertex1-edgeX-vertex1 - it is not true since it is the same edge-@rid from the first result and also it is NOT a self edge: jonn Smith --phoneCallX-- jonn Smith

The query:

MATCH {class:person, as:E1, where:( (   firstName IN ['John']   ) )}.bothE(){class:phoneCall, as:R0}.bothV(){class:person, as:E0, where:( (   lastName IN ['Smith']   ) )} RETURN $paths

I think it is happening because of the "both()" method with the fact that the first vertex apply to both filters:

  1. firstName IN ['John']
  2. List item lastName IN ['Smith']

But still - I meant to find all paths of "John-phoneCall-Smith" and I got an edge (that doesn't exist) between this John to himself just because his name is Smith (which should be the condition of the OTHER entity of this relation) )

Please help me - what do I do wrong?


Solution

  • You can explicitly specify that the two vertices have to be different. The syntax is, in the WHERE condition of E2, $matched.E1 <> $currentMatch

    MATCH 
       {class:person, as:E1, where:( (   firstName IN ['John']   ) )}
          .bothE(){class:phoneCall, as:R0}
          .bothV(){class:person, as:E0, where:(lastName IN ['Smith'] AND $matched.E1 <> $currentMatch)} 
    RETURN $paths