formations/cesi/intro_big_data/ressources/cayley-compose/queries.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

# Gizmo
## Trouver les plats préférés de chaque personne
```js
g.V().Has("<has_favorite_dish>").Tag("source").Out("<has_favorite_dish>").Tag("target").All()
```
## Afficher l'ensemble des relations du réseau social
```js
g.V().Has("<friend_of>").Tag("source").Out("<friend_of>").Tag("target").All()
```
## Trouver les amis des amis de Jean
```js
g.V("<jean>").Tag("source").Out("<friend_of>").ForEach(function(directFriend) {
g.Emit({ id: directFriend.id, source: "<jean>", target: directFriend.id });
g.V(directFriend.id).Out("<friend_of>").ForEach(function(friendOfFriend) {
g.Emit({id: friendOfFriend.id, source: directFriend.id, target: friendOfFriend.id });
});
});
```
## Trouver les amis des amis de Jean qui aiment un plat commun
```js
var jean = g.V("<jean>");
var jeanFavoriteDishes = jean.Out("<has_favorite_dish>");
jean.Out("<friend_of>").ForEach(function(directFriend) {
g.V(directFriend.id).Out("<friend_of>").ForEach(function(friendOfFriend) {
jeanFavoriteDishes.Intersect(g.V(friendOfFriend.id).Out("<has_favorite_dish>")).ForEach(function(favoriteDish) {
g.Emit({ id: directFriend.id, source: "<jean>", target: directFriend.id });
g.Emit({ id: friendOfFriend.id, source: directFriend.id, target: friendOfFriend.id });
g.Emit({ id: favoriteDish.id, source: friendOfFriend.id, target: favoriteDish.id });
});
});
});
```