Module: Elasticsearch::Model::Adapter::Lycra::Multiple::Records
- Defined in:
- lib/elasticsearch/model/adapters/lycra/multiple.rb
Instance Method Summary collapse
- #__documents_by_type ⇒ Object
- #__documents_for_klass(klass, ids) ⇒ Object
- #__ids_by_type ⇒ Object
- #__type_for_hit(hit) ⇒ Object
-
#records ⇒ Object
documents.compact end.
Instance Method Details
#__documents_by_type ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/elasticsearch/model/adapters/lycra/multiple.rb', line 30 def __documents_by_type result = __ids_by_type.map do |klass, ids| documents = __documents_for_klass(klass, ids) ids = documents.map(&:id).map(&:to_s) mapped = [ klass, Hash[ids.zip(documents)] ] mapped end Hash[result] end |
#__documents_for_klass(klass, ids) ⇒ Object
41 42 43 |
# File 'lib/elasticsearch/model/adapters/lycra/multiple.rb', line 41 def __documents_for_klass(klass, ids) return klass.subject_type.where(klass.primary_key => ids) end |
#__ids_by_type ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch/model/adapters/lycra/multiple.rb', line 45 def __ids_by_type ids_by_type = {} response.response["hits"]["hits"].each do |hit| type = __type_for_hit(hit) ids_by_type[type] ||= [] ids_by_type[type] << hit[:_id] end ids_by_type end |
#__type_for_hit(hit) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/elasticsearch/model/adapters/lycra/multiple.rb', line 56 def __type_for_hit(hit) @@__types ||= {} @@__types[ "#{hit[:_index]}::#{hit[:_type]}" ] ||= begin ::Lycra::Document::Registry.all.detect do |document| hit[:_index] =~ /\A#{document.index_name}(-[a-zA-Z0-9]+)?\Z/ && document.document_type == hit[:_type] end end end |
#records ⇒ Object
documents.compact end
20 21 22 23 24 25 26 27 28 |
# File 'lib/elasticsearch/model/adapters/lycra/multiple.rb', line 20 def records documents_by_type = __documents_by_type records = response.response["hits"]["hits"].map do |hit| documents_by_type[ __type_for_hit(hit) ][ hit[:_id] ]#.subject end records.compact end |