0.0
No commit activity in last 3 years
No release in over 3 years
This ruby on rails gem makes it easy to store polymorphic structure information --- parents, children, ancestors, descendants, ... --- in a neo4j graph database parallel to using ActiveRecord.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
>= 3.2
 Project Readme

Neo4jAncestry

Build Status

This ruby on rails gem makes it easy to store polymorphic structure information—parents, children, ancestors, descendants, …—in a neo4j graph database parallel to using ActiveRecord.

All relevant information is stored in your default ActiveRecord database, including the parent-child relationships. But, in addition, the structure information is also stored in a neo4j graph database in order to use its power of fast graph traversing queries.

Usage

TODO: Write usage instructions here

  • use has_neo4j_ancestry in nodes
  • use methods like ancestors or ancestor_groups
  • special methods like find_shortest_path_to(other_node).

Graph Data Browser

You can use Neo4j's excellent web interface when the daemon is running:

Bildschirmfoto 2014 11 09 Um 02.47.29

From there, you can use Cypher queries like this producing the above:

match
  (group1:Group {active_record_id: 2978}),
  (group2:Group {active_record_id: 2983}),
  paths = (group1)-[:is_parent_of*1..100]->(group2)
return paths
order by length(paths)

This is an excellen cheat sheet for cypher: http://neo4j.com/docs/2.0/cypher-refcard/

Installation

Installing Java 7 JDK

First, make sure, Java 7 JDK is installed. You can check using java -version. If you need to install it:

  • Mac OS

    • Install the JDK, not the JRE: Download

    • Set your JAVA_HOME environment variable in the .zshenv or .bashrc like this:

      # .zshenv
      export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
  • Ubuntu/Debian GNU Linux

    • aptitude install openjdk-7-jre-headless

Including the gem

Add the gem to your application's Gemfile:

# Gemfile
# ...
gem 'neo4j_ancestry'

And then execute:

# bash
bundle install

Installing Neo4j

This will install two instances of the neo4j database inside the db directory of your app—one instance for development, one for test. The data of the database instances are stored in data subdirectories.

# bash
bundle exec rake neo4j:install neo4j:get_spatial neo4j:setup neo4j:start

ActiveRecord Migration

Next, migrate the ActiveRecord database in order to add a table for direct links between objects. This way, all relevant information is stored within the ActiveRecord database. This way, the whole graph database could be reconstructed from the ActiveRecord database.

# bash
bundle exec rake neo4j_ancestry:install:migrations
bundle exec rake db:migrate

Underlying Technology

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running the Gem's Specs Locally

Symlink the Gemfile according to the Rails version you would like to use:

# bash
rm Gemfile Gemfile.lock
ln -s rails3.2.Gemfile Gemfile   # for Rails 3
ln -s rails4.Gemfile Gemfile     # for Rails 4  (default)

Next, install the dependencies and run the specs.

# bash
bundle install
bundle exec rake neo4j_ancestry:db:test:prepare
bundle exec rake

Author, License

© 2013-2014, Sebastian Fiedlschuster

Released under the MIT License.