Skip to content
This repository

Expose Cypher Queries on Traversal Methods and Rules #181

Closed
andreasronge opened this Issue April 16, 2012 · 0 comments

1 participant

Andreas Ronge
Andreas Ronge
Owner

The result of this issue: https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3AWrapper-Rules-and-Functions

Declared Traversals and Rules

class Monster < Neo4j::Rails::Model
  rule(:dangerous){|x| x[:strength] > 15}
end

class Dungeon < Neo4j::Rails::Model
  property :level, :type => Fixnum, :index => :exact
  has_n(:monsters).to(Monster)
end

Monster.all.query #=> an Enumeration of all monsters nodes by using Cypher and traversing the 'class node'/rule node
Monster.all.query{|x| x[:age] < 20} => Same as above but adds a where statement

d = Dungeon.find_by_level(2)
d.monsters.query  #=> should use Cypher to return the has_n relationship
d.monsters.dangerous.query  #=> same as above but also use the dangerous rule declared on Monster class.

The d.monster.dangerous method is available on the Traversal/Neo4j::Rails::Relationship::NodeDSL (?), since there is a #to relationship declared to Monster

It's also be possible to use MATCH clauses (or any other cypher construct) in the query method block since the query block is evaluated by the Neo4j::Cypher class.

Notice, by using cypher the traversal will be executed in the Java layer => probably much better performance.

General Purpose Traverals

the outgoing, incoming traversals can be translated to Cypher queries.
Example

  node.outgoing(:foo).query{|x| x[:age] > 42}
  node.outgoing(:foo).query{|x| q = x.outgoing(:bar); x[:thing] == 'something'; q.distinct}

As shown about, it is also allowed to use the outgoing, incoming and both instead of using the <, > <=> operators.
That means that this will work:

  Neo4j.query{ lookup(Person, "name", "kalle").outgoing(Person.friends)[:age] > 42} 

will work.

see also - http://groups.google.com/group/neo4jrb/browse_thread/thread/849d43bf36ea4fe

Andreas Ronge andreasronge referenced this issue from a commit in andreasronge/neo4j-core April 16, 2012
Andreas Ronge Started to integrate cypher queries in outgoing, incoming, both trave…
…rsals andreasronge/neo4j#181

It is now also possible to create several relationship in one go
  node.outgoing(:foo).incoming(:bar).both(:baaz) << other_node
  node.outgoing(:foo).incoming(:bar).both(:baaz).new(other_node, rel_props)
287c423
Andreas Ronge andreasronge referenced this issue from a commit in andreasronge/neo4j-core April 17, 2012
Andreas Ronge Support for cypher query expressed as a Hash, e.g. outgoing(:foo).que…
…ry(:name => 'foo') - traversals andreasronge/neo4j#181
7ab57d2
Andreas Ronge andreasronge referenced this issue from a commit in andreasronge/neo4j-wrapper April 17, 2012
Andreas Ronge Cypher Traversal and Rules andreasronge/neo4j#181
Support for things like getting the rooms for a dungeon where there are dangerous monsters using rules:
@dungeon.monsters.dangerous { |m| rooms = m.incoming(Room.monsters); rooms}
662e0ad
Andreas Ronge andreasronge referenced this issue from a commit in andreasronge/neo4j-wrapper April 18, 2012
Andreas Ronge Added RSpecs for sorting has_n relationship with cypher DSL andreasro…
…nge/neo4j#181

Some refactoring and exposed a method creating rules method on traversal which can be used by neo4j gem.
5efe932
Andreas Ronge andreasronge referenced this issue from a commit in andreasronge/neo4j-wrapper April 17, 2012
Andreas Ronge Cypher Traversal and Rules andreasronge/neo4j#181
Support for things like getting the rooms for a dungeon where there are dangerous monsters using rules:
@dungeon.monsters.dangerous { |m| rooms = m.incoming(Room.monsters); rooms
7ed29ba
Andreas Ronge andreasronge referenced this issue from a commit April 18, 2012
Andreas Ronge Cypher and Rule integration #181
Support for things like @dungeon.monsters.dangerous { |m| m[:weapon?] == 'sword' }
39b2101
Andreas Ronge andreasronge closed this in d321a27 April 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.