README.rdoc

Path: README.rdoc
Last Update: Thu Dec 22 22:42:30 +0000 2016

neo4jr-simple

A simple, ready to go JRuby wrapper for the Neo4j graph database engine which provides:

  • The Neo4j Core Java Library (required and ready to use)
  • Raw access to the Java API (using Neo4j::DB.instance )
  • Extensions to the Java API to make node manipulation and traversal more rubyesque
  • Working specs
  • Loaded Neo4j sample database with IMDB data
  • Nothing more then Neo4j goodness

Prerequisites

  • Java
  • JRuby

Recommend way of installing JRuby

  1. Install RVM: rvm.beginrescueend.com/
  2. Install Jruby using rvm: rvm install jruby
  3. Switch ruby to JRuby: rvm use jruby

Getting Started

Basic Node creation:

   Neo4jr::DB.execute do |neo|
     node = neo.createNode
     node[:name] = 'Deiters, Matt'
   end

Retrieve a Node:

   Neo4jr::DB.execute do |neo|
     node = neo.getNodeById(1234)
   end

Find a Node by some value you control:

   Neo4jr::DB.execute do |neo|
     # If you add a property 'identifier' to a node, the value can be used to retrieve the node by
     # This can by an id or string but the value must be unique to this node
     # e.g. node[:identifier] = user.id
     node = neo.find_node_by_identifier(user.id)
   end

Traverse Database from a node:

   Neo4jr::DB.execute do |neo|
     philip_seymour_hoffman = neo.getNodeById(1102)

     order         = Neo4jr::Order::BREADTH_FIRST
     stop_when     = Neo4jr::StopEvaluator::END_OF_GRAPH
     return_when   = Neo4jr::ReturnableEvaluator::ALL
     relationships = Neo4jr::RelationshipType.outgoing(:acted_in)

     traverser = philip_seymour_hoffman.traverse(order, stop_when, return_when, relationships)
     traverser.each do |node|
       #...
     end
   end

Use command line shell to query and modify the graph:

  neosh -path <path_to_neo_db>

Contributors

  https://github.com/mdeiters
  https://github.com/klobuczek
  https://github.com/gregormelhorn

Copyright (c) 2009 Matthew Deiters. See LICENSE for details.

[Validate]