Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple unified API that can access both the server and embedded Neo4j database. Used by the neo4j gem
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config/neo4j
lib
spec
.gitignore
.travis.yml
.yardopts
Gemfile
README.rdoc
Rakefile
neo4j-core.gemspec

README.rdoc

Neo4j-core

This gem only contains the JRuby mapping of the Neo4j graph database. The neo4j.rb gem will be split up into three gems, neo4j-core, neo4j-wrapper and neo4j. This gem will be included by neo4j 2.0.0 gem.

This gem contains two modules: Neo4j and Neo4j::Core The Neo4j module is public and the Neo4j::Core(::*) are internal modules.

Documentation

The public API

{Neo4j::Node} The Java Neo4j Node

{Neo4j::Relationship} The Java Relationship

{Neo4j} The Database

Neo4j::Cypher} Cypher Query DSL, see {Neo4j Wiki

{Neo4j::Algo} Included algorithms, like shortest path

Custom Index

You can create your own indexer.

class MyIndex
  extend Neo4j::Core::Index::ClassMethods
  include Neo4j::Core::Index

  node_indexer do
    index_names :exact => 'myindex_exact', :fulltext => 'myindex_fulltext'
    trigger_on :myindex => true, :things => ['a', 'b']
  end

  index :name
end

All nodes with the property myindex == true or property things 'a' or 'b' will be indexed using this index.

Exampel:

n = Neo4j::Node.new(:myindex = true, :name => 'foo')
MyIndex.find('name: foo').first #=> n

Cypher

Example:

Neo4j.query { node(3) }

Example with parameters:

Neo4j.query(Neo4j.ref_node} do |ref|
   ref <=> :x
   :x
end

Notice

  • The last statement in the expression will be the return value.

  • You can skip the start, match, where and ret (they are just empty methods).

Cypher Examples

“START n0=node(3) RETURN n0”

Neo4j.query do
  start n = node(3)
  ret n
end
# the above is same as:
Neo4j.query { node(3) }

“START n0=node(42) RETURN n0”

node(Neo4j::Node.new)

“START r0=relationship(3,4) RETURN r0”

rel(3,4)

“START n0=node(3) MATCH (n0)–(x) RETURN x”

start n = node(3)
match n <=> :x
ret :x

“START n0=node(3) MATCH (n0)–(v0) RETURN v0”

x = node
n = node(3)
match n <=> x
ret x

“START n0=node(3) MATCH (n0)–(v0) RETURN v0.name”

x = node
n = node(3)
match n <=> x
ret x[:name]

“START n0=node(1) RETURN n0.name AS SomethingTotallyDifferent”

x = node(1)
x[:name].as('SomethingTotallyDifferent')

“START n0=node:fooindex_exact(name:A) RETURN n0”

query(FooIndex, "name:A")

“START n0=node:fooindex_fulltext(desc=”A“) RETURN n0”

lookup(FooIndex, "desc", "A")

“START n0=node(1),n1=node(2) RETURN n0,n1”

[node(1), node(2)]

“START n0=node(3) MATCH (n0)–>©–>(d) RETURN c”

node(3) >> node(:c) >> :d
:c

“START n0=node(3) MATCH (n0)-[r]->(x) RETURN r”

node(3) > :r > :x
:r

“START n0=node(3) MATCH (n0)-[r:friends]->(x) RETURN r”

r = rel('r:friends').as(:r)
node(3) > r > :x
r

“START n0=node(3,1) WHERE n0.age < 30 RETURN n0”

n=node(3, 1)
where n[:age] < 30
ret n

“START n0=node(3,4) WHERE n0.desc = ”hej“ RETURN n0”

n=node(3, 4)
n[:desc] == "hej"
n

“START n0=node(3) MATCH (n0)<-[:knows]-© RETURN c”

a=node(3)
a < ':knows' < :c
:c

“START n0=node(3) MATCH (n0)-[r]->(v1) WHERE type® =~ /K.*/ RETURN r”

n=node(3)
n > (r=rel('r')) > node
r.rel_type =~ /K.*/
r

“START n0=node(3) MATCH m2 = (n0)–>(b) RETURN b,length(m2)”

p = node(3) >> :b; [:b, p.length]

“START n0=node(1) MATCH (n0)–>(b) RETURN distinct n0”

n=node(1); n>>:b; n.distinct

“START n0=node(2) MATCH (n0)–>(x) RETURN n0,count(*)”

n = node(2))>>:x
[n, count]

“START n0=node(2,3,4) RETURN sum(n0.property)”

n=node(2, 3, 4)
n[:property].sum

“START n0=node(2) MATCH (n0)–>(b) RETURN count(distinct n0.eyes)”

n=node(2); n>>:b
n[:eyes].distinct.count

“START n0=node(3,4,5) RETURN ID(n0)”

node(3, 4, 5).neo_id

“START n0=node(2) WHERE any(x in n0.array WHERE x = ”one“) RETURN n0”

a = node(2)
a[:array].any? { |x| x == 'one' }
a

“START n0=node(3),n1=node(4),n2=node(1) MATCH m4 = (n0)–>(n1)–>(n2) RETURN extract(x in nodes(m4) : x.age)”

a=node(3)
b=node(4)
c=node(1)
p=a>>b>>c
p.nodes.extract { |x| x[:age] }

“START n0=node(3) WHERE abs(n0.x) = 3 RETURN n0”

a=node(3); a[:x].abs==3
a

“START n0=node(3,4,5,1,2) RETURN n0 ORDER BY n0.name SKIP 1 LIMIT 2”

a=node(3,4,5,1,2); ret(a).asc(a[:name]).skip(1).limit(2)
# o same as
a=node(3,4,5,1,2); ret a, :asc => a[:name], :skip => 1, :limit => 2

For more examples, see the RSpecs

Creates Your Own Wrapper

Todo, see {Neo4j::Core::Wrapper}

Changes

Changes from the neo4j.rb

  • Use of YARD instead of RDoc

  • Some tidy up of the API and code (e.g. Neo4j::Node#rels methods)

  • Change of Ruby module structure.

  • More RSpecs and more use of mocking combined with real testing of the Java layer

  • Make sure that we retrieve relationships and nodes lazy if possible.

  • Cypher Query DSL

Something went wrong with that request. Please try again.