Skip to content
Joey edited this page Dec 30, 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 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 you build a route, no work is done on the graph until you execute it.
  • You 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). In addition to that, edge routes can be filtered by the label of the edge.

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

Route Types

The methods supported by a routes depend on the type of its items. Pacer defines the following commonly-used route types:

  • Vertex
  • Edge
  • Mixed (vertices and/or edges)
  • Path (Array of alternating vertices and edges)
  • Array
  • String

You can see how these routes are defined here and here.

Home

Clone this wiki locally