Skip to content

Instantly share code, notes, and snippets.

@andreasronge
Created October 23, 2009 18:35
Show Gist options
  • Save andreasronge/217094 to your computer and use it in GitHub Desktop.
Save andreasronge/217094 to your computer and use it in GitHub Desktop.
How do I find All actors that acted in these 2 movies, or 3 movies?
require 'model' # from the example/imdb neo4j.rb example
class Actor
def acted_in_cool_movies
traverse.outgoing(:acted_in).find_all {|movie| movie.relationship?(:cool_movies, :incoming)}
end
end
cool_movies = Node.new
all_cool_movies = [m1,m2] # m1,m2 are two movies - defined somewhere else
all_cool_movies.each {|movie| cool_movies.relationships.outgoing(:cool_movies) << movie}
cool_movies.traverse.outgoing(:cool_movies).incoming(:acted_in).depth(2).filter{ respond_to?(:acted_in_cool_movies) and acted_in_cool_movies.size == all_cool_movies.size}.each {|n| puts n}
# Simple solution but inefficient solution
m1.actors.to_a & m2.actors.to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment