Sha256: 7b7edbcbd28fef87bb9139b411b4e2386b72de2d4ea6983a4d41127f9a02ff87
Contents?: true
Size: 667 Bytes
Versions: 2
Compression:
Stored size: 667 Bytes
Contents
module Neoid class SearchSession def initialize(response, *models) @response = response || [] @models = models end def hits @response.map { |x| Neography::Node.new(x) } end def ids @response.map { |x| x['data']['ar_id'] } end def results models_by_name = @models.inject({}) { |all, curr| all[curr.name] = curr; all } ids_by_klass = @response.inject({}) do |all, curr| klass_name = curr['data']['ar_type'] (all[models_by_name[klass_name]] ||= []) << curr['data']['ar_id'] all end ids_by_klass.map { |klass, ids| klass.where(id: ids) }.flatten end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
neoid-0.2.1 | lib/neoid/search_session.rb |
neoid-0.2.0 | lib/neoid/search_session.rb |