I'm trying to perform the following graph query in orientdb and it works
select nearTo as c1,nearTo.id,nearTo.name, count(nearTo) as repetition,level,path from (
MATCH {class: GNode, where: (id = 5)}
-has-> {as: connection, while: ($depth <= 1), where: ($depth <= 1)}
-has-> {as: nearTo, while: ($depth < 3), where: ($depth > 1), depthAlias: level,pathAlias: path}
RETURN nearTo,level,path
)
group by nearTo order by repetition desc
The problem with this query is that it matches the nodes in the connection too if connection flows back, so i tried the following queries and none worked
1)
select nearTo,nearTo.id,nearTo.name, count(nearTo) as repetition,level,path from (
MATCH {class: GNode, where: (id = 5)}
-has-> {as: connection, while: ($depth < 2), where: ($depth <= 1)}
-has-> {as: nearTo, while: ($depth < 4), where: ($depth > 1), depthAlias: level,pathAlias: path}
RETURN nearTo,level,path
) where nearTo not in [connection]
group by nearTo order by repetition desc
2)
select nearTo,nearTo.id,nearTo.name, count(nearTo) as repetition,level,path from (
MATCH {class: GNode, where: (id = 5)}
-has-> {as: connection, while: ($depth < 2), where: ($depth <= 1)}
-has-> {as: nearTo, while: ($depth < 4), where: ($depth > 1), depthAlias: level,pathAlias: path}
RETURN nearTo,level,path
) where nearTo not in [(MATCH {class: GNode, where: (id = 5)}
-has-> {as: c, while: ($depth < 2), where: ($depth <= 1)} RETURN c)]
group by nearTo order by repetition desc
3)
select nearToFinal,nearToFinal.id,nearToFinal.name, count(nearToFinal) as repetition,level,path from (
MATCH {class: GNode, where: (id = 5)}
-has-> {as: connection, while: ($depth < 2), where: ($depth <= 1)}
-has-> {as: nearTo, while: ($depth < 4), where: ($depth > 1), depthAlias: level,pathAlias: path}
-has-> NOT {as:nearToFinal}
RETURN nearToFinal,level,path
)
group by nearToFinal order by repetition desc
Alternatively the below query gives me the negated result, but unable to order based on repetition as alias not supported for from clause
select * from (TRAVERSE out("has") FROM #27:1 MAXDEPTH 4 STRATEGY BREADTH_FIRST) where @rid NOT IN (TRAVERSE out("has") FROM #27:1 MAXDEPTH 1)
Any help is much appreciated. Same case with gremlin query is also fine.