Skip to content

Commit 0279804

Browse files
JDRomano2claude
andcommitted
Fix path search: lower BFS bound to 1 so adjacent nodes return a path
Memgraph's BFS returns only the single shortest path, so a lower bound of 2 made the query return nothing whenever the two nodes were directly connected (it found the 1-hop shortest path, saw it was below the floor, and gave up instead of searching for a longer alternative). Lowering the bound to 1 restores the pre-Memgraph-migration behavior of returning the shortest path whenever one of length <= 10 exists. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a1761f1 commit 0279804

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

web/packages/api/models/paths.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ const findPathByIds = function findPathByIds(session, fromId, toId) {
1616
});
1717
}
1818

19-
// Memgraph supports algo.shortestPath via openCypher's MATCH with shortest;
20-
// here we use a length-bounded variable-length pattern and ORDER BY length(p).
19+
// Memgraph's BFS returns the single shortest path between the anchored
20+
// endpoints. The lower bound must be 1: a floor of 2 makes BFS return
21+
// nothing whenever the two nodes are directly connected (it finds the
22+
// 1-hop shortest path, sees it is below the floor, and gives up rather
23+
// than searching for a longer alternative).
2124
const query = [
22-
'MATCH p = (n)-[*BFS 2..10]-(m)',
25+
'MATCH p = (n)-[*BFS 1..10]-(m)',
2326
'WHERE id(n) = $from AND id(m) = $to',
2427
'RETURN p',
2528
'ORDER BY size(relationships(p)) ASC',

0 commit comments

Comments
 (0)