-
Notifications
You must be signed in to change notification settings - Fork 27
Routes
joeyfreund edited this page Dec 31, 2014
·
5 revisions
Pacer is all about graph traversals. To traverse the graph with Pacer, you create a Route.
A route is a collection of items (e.g. vertices or edges) that is composable, lazily-loaded and reusable:
- Routes implement Ruby's Enumerable module (with certain exceptions).
- We define routes by composing them with one another.
- When we build a route, no work is done on the graph until you execute it.
- We can execute a route repeatedly.
Say we want to find all flights, with 1 connection, from NYC to LA.
In order to achieve that, we will define a route that looks like this:
In Pacer, the code that creates (and executes) this route will look like this:
g.v(city: 'NYC').out_e.in_v.out_e.in_v(city: 'LA').paths
The most commonly used routes in Pacer are
-
Vertex routes that support the
out_e
andin_e
methods. -
Edge routes that support the
in_v
andout_v
methods.
The common usage patterns are:
# Traversing the graph by following outgoing edges
vertices.out_e.in_v
# Traversing the graph by following incoming edges
vertices.in_e.out_v
# Traversing the graph in both directions
vertices.out_e.in_v.in_e.out_v
Both, vertex and edge, routes can be filtered based on properties value(s). Edge routes can also be filtered by edge label.
For example, we can define the following routes in a social network graph.
# Find users by name
graph.v(type: 'user', name: 'Bob')
# Find users that Bob follows
graph.v(type: 'user', name: 'Bob').out_e(:follows).in_v(type: 'user')
# Find followers of users that Bob follows
graph.v(type: 'user', name: 'Bob').out_e(:follows).in_v(type: 'user').in_e(:follows).out_v(type: 'user')
- Introduction
- The Basics
- [Traversals](Graph Traversals with Pacer Routes)
- [Route Types](Route Types)