Skip to content
mdeiters edited this page Sep 13, 2010 · 12 revisions

neo4jr-social is meant to be a simple service offering basic neo4j persistance and querying capabilities in a language agnostic way. You will likely want to do more advance things like custom traversing of your graph. To support this neo4jr-social auto loads extensions from a predefined location. Using this option allows you to add arbitrary methods to the neo4jr-social service.

How to configure extensions

  • By default neo4jr-social will load any jruby (files ending in .rb) files located at:
    ~/.neo4jr-social
  • You can also specify a different location to load ruby files from by setting the neo4jr_extensions environment variable. i.e.
    export neo4jr_extensions=/path/to/your/extensions
  • Or for you java people out there, you can set system property neo4jr.extensions

Example Extension

Creating extensions are super easy

  • Create a file i.e.
    vim ~/.neo4jr-social/test.rb
  • Paste the following into test.rb,

    module Neo4jr
    class Service < Sinatra::Base
    get ‘/my_custom_action/:node_id’ do
    Neo4jr::DB.execute do |neo|
    node = neo.getNodeById(params[‘node_id’].to_s)
    order = Neo4jr::Order::BREADTH_FIRST
    stop_when = Neo4jr::StopEvaluator::END_OF_GRAPH
    return_when = Neo4jr::Return.when do |current_node|
    true
    end
    relationships = Neo4jr::RelationshipType.outgoing(:acted_in)
    traverser = node.traverse(order, stop_when, return_when, relationships)
    traverser.map.to_json
    end
    end
    end
    end
  • Restart the service
  • Test the new GET request /my_custom_action/123
Clone this wiki locally