Class: Sunspot::Rails::Adapters::MongoidDataAccessor

Inherits:
Adapters::DataAccessor
  • Object
show all
Defined in:
lib/sunspot/rails/adapters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#selectObject

options for the find



33
34
35
# File 'lib/sunspot/rails/adapters.rb', line 33

def select
  @select
end

Instance Method Details

#load(id) ⇒ Object

Get one Mongoid document instance out of the database by ID

Parameters

id<String>

Database ID of model to retreive

Returns

Mongoid model



58
59
60
# File 'lib/sunspot/rails/adapters.rb', line 58

def load(id)
  @clazz.find(BSON::ObjectID.from_string(id)) rescue nil
end

#load_all(ids) ⇒ Object

Get a collection of Mongoid instances out of the database by ID

Parameters

ids<Array>

Database IDs of models to retrieve

Returns

Array

Collection of Mongoid models



73
74
75
76
77
78
79
80
# File 'lib/sunspot/rails/adapters.rb', line 73

def load_all(ids)
  options = options_for_find
  if options[:select]
    @clazz.only(options[:select]).where(:_id.in => ids.map { |id| BSON::ObjectId.from_string(id) })
  else
    @clazz.where(:_id.in => ids.map { |id| BSON::ObjectId.from_string(id) })
  end
end