Skip to content

Instantly share code, notes, and snippets.

@Swimminschrage
Created April 24, 2015 22:20
Show Gist options
  • Save Swimminschrage/499895542f57e356bc3c to your computer and use it in GitHub Desktop.
Save Swimminschrage/499895542f57e356bc3c to your computer and use it in GitHub Desktop.
neo4j_adapter.rb
require 'sunspot'
require 'sunspot/rails'
# == Examples:
#
# class Post
# include Neo4j::ActiveNode
# field :title
#
# include Sunspot::Neo4j
# searchable do
# text :title
# end
# end
#
module Sunspot
module Neo4j
def self.included(base)
base.class_eval do
extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
end
end
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
criteria(id).first
end
def load_all(ids)
criteria(ids)
end
private
def criteria(id)
@clazz.find(id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment