Skip to content
joeyfreund edited this page Dec 31, 2014 · 5 revisions

Routes

Pacer is all about graph traversals. To traverse the graph with Pacer, you create a Route.

What is 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.

Example

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:



Routes Example



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 Basics

Traversing

The most commonly used routes in Pacer are

  • Vertex routes that support the out_e and in_e methods.
  • Edge routes that support the in_v and out_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

Filtering

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')

Home

Clone this wiki locally