I am using LevelGraph (https://github.com/mcollina/levelgraph) to store connected items. My items are connected in the following way:
db.put([{
subject: "matteo",
predicate: "friend",
object: "daniele"
}, {
subject: "daniele",
predicate: "friend",
object: "bob"
}, {
subject: "bob",
predicate: "friend",
object: "marco"
}, {
subject: "marco",
predicate: "friend",
object: "fred"
}, {
subject: "fred",
predicate: "friend",
object: "joe"
}, {
subject: "joe",
predicate: "friend",
object: "david"
}], function () {});
I'd like to write a function to retrieve the nth-friend-of-friend of a particular person. For example here, the 6th-friend-of-a-friend of matteo would be david.
I know levelgraph has a search function built in:
db.search([{
subject: "matteo",
predicate: "friend",
object: db.v("x")
}, {
subject: db.v("x"),
predicate: "friend",
object: db.v("y")
}, {
subject: db.v("y"),
predicate: "friend",
object: db.v("z")
}], function(err, results) {
console.log(results);
});
Here, I would get the 3rd firend of a friend but I am not sure I get how to use it to retrieve the nth friend of a friend.
Is there a way to elegantly compound the search to retrieve the n-th connection?