lib/elasticsearch/model/adapters/multiple.rb in elasticsearch-model-0.1.7 vs lib/elasticsearch/model/adapters/multiple.rb in elasticsearch-model-0.1.8
- old
+ new
@@ -16,13 +16,15 @@
# @note The order of results in the Elasticsearch response is preserved
#
def records
records_by_type = __records_by_type
- response.response["hits"]["hits"].map do |hit|
+ records = response.response["hits"]["hits"].map do |hit|
records_by_type[ __type_for_hit(hit) ][ hit[:_id] ]
end
+
+ records.compact
end
# Returns the collection of records grouped by class based on `_type`
#
# Example:
@@ -47,16 +49,16 @@
# Returns the collection of records for a specific type based on passed `klass`
#
# @api private
#
def __records_for_klass(klass, ids)
- adapter = __adapter_name_for_klass(klass)
+ adapter = __adapter_for_klass(klass)
- case adapter
- when Elasticsearch::Model::Adapter::ActiveRecord
+ case
+ when Elasticsearch::Model::Adapter::ActiveRecord.equal?(adapter)
klass.where(klass.primary_key => ids)
- when Elasticsearch::Model::Adapter::Mongoid
+ when Elasticsearch::Model::Adapter::Mongoid.equal?(adapter)
klass.where(:id.in => ids)
else
klass.find(ids)
end
end
@@ -98,10 +100,10 @@
# Returns the adapter registered for a particular `klass` or `nil` if not available
#
# @api private
#
- def __adapter_name_for_klass(klass)
+ def __adapter_for_klass(klass)
Adapter.adapters.select { |name, checker| checker.call(klass) }.keys.first
end
end
end
end