Fix nested MATCH path evaluations with WHERE conditions
@@ -60,15 +60,21 @@ public class MatchMultiEdgeTraverser extends MatchEdgeTraverser {
Object nextSteps = method.execute(o, possibleResults, iCommandContext);
if (nextSteps instanceof Collection) {
((Collection) nextSteps).stream().map(x -> toOResultInternal(x)).filter(Objects::nonNull)
+ .filter(x -> matchesCondition((OResultInternal) x, sub.getFilter(), iCommandContext))
.forEach(i -> rightSide.add((OResultInternal) i));
} else if (nextSteps instanceof OIdentifiable) {
- rightSide.add(new OResultInternal((OIdentifiable) nextSteps));
+ OResultInternal res = new OResultInternal((OIdentifiable) nextSteps);
+ if (matchesCondition(res, sub.getFilter(), iCommandContext)) {
+ rightSide.add(res);
+ }
} else if (nextSteps instanceof OResultInternal) {
+ if (matchesCondition((OResultInternal) nextSteps, sub.getFilter(), iCommandContext)) {
rightSide.add((OResultInternal) nextSteps);
+ }
} else if (nextSteps instanceof Iterable) {
for (Object step : (Iterable) nextSteps) {
OResultInternal converted = toOResultInternal(step);
- if (converted != null) {
+ if (converted != null && matchesCondition(converted, sub.getFilter(), iCommandContext)) {
rightSide.add(converted);
}
}
@@ -76,7 +82,7 @@ public class MatchMultiEdgeTraverser extends MatchEdgeTraverser {
Iterator iterator = (Iterator) nextSteps;
while (iterator.hasNext()) {
OResultInternal converted = toOResultInternal(iterator.next());
- if (converted != null) {
+ if (converted != null && matchesCondition(converted, sub.getFilter(), iCommandContext)) {
rightSide.add(converted);
}
}
@@ -92,6 +98,17 @@ public class MatchMultiEdgeTraverser extends MatchEdgeTraverser {
return (Iterable) result;
}
+ private boolean matchesCondition(OResultInternal x, OMatchFilter filter, OCommandContext ctx) {
+ if (filter == null) {
+ return true;
+ }
+ OWhereClause where = filter.getFilter();
+ if (where == null) {
+ return true;
+ }
+ return where.matchesFilters(x, ctx);
+ }
+
private OResultInternal toOResultInternal(Object x) {
if (x instanceof OResultInternal) {
return (OResultInternal) x;
