Commit 1d8fc2992fe170d5ac4faf4be2144fcafca1d593

Authored by Andrew Kane
2 parents 267645f5 b5e3de6a

Merge branch 'subvertallchris-master'

Showing 1 changed file with 17 additions and 11 deletions   Show diff stats
lib/searchkick/results.rb
... ... @@ -26,17 +26,7 @@ module Searchkick
26 26 if options[:includes]
27 27 records = records.includes(options[:includes])
28 28 end
29   - results[type] =
30   - if records.respond_to?(:primary_key) and records.primary_key
31   - # ActiveRecord
32   - records.where(records.primary_key => grouped_hits.map{|hit| hit["_id"] }).to_a
33   - elsif records.respond_to?(:all) and records.all.respond_to?(:for_ids)
34   - # Mongoid 2
35   - records.all.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
36   - else
37   - # Mongoid 3+
38   - records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
39   - end
  29 + results[type] = results_query(records, grouped_hits)
40 30 end
41 31  
42 32 # sort
... ... @@ -143,5 +133,21 @@ module Searchkick
143 133 @response["hits"]["hits"]
144 134 end
145 135  
  136 + private
  137 +
  138 + def results_query(records, grouped_hits)
  139 + if records.respond_to?(:primary_key) and records.primary_key
  140 + # ActiveRecord
  141 + records.where(records.primary_key => grouped_hits.map{|hit| hit["_id"] }).to_a
  142 + elsif records.respond_to?(:all) and records.all.respond_to?(:for_ids)
  143 + # Mongoid 2
  144 + records.all.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
  145 + elsif records.respond_to?(:queryable)
  146 + # Mongoid 3+
  147 + records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a
  148 + else
  149 + raise "Not sure how to load records"
  150 + end
  151 + end
146 152 end
147 153 end
... ...