lib/search_flip/response.rb in search_flip-3.9.0 vs lib/search_flip/response.rb in search_flip-4.0.0.beta
- old
+ new
@@ -154,21 +154,20 @@
current_page + 1
end
# Returns the results, ie hits, wrapped in a SearchFlip::Result object
- # which basically is a Hashie::Mash. Check out the Hashie docs for further
- # details.
+ # which basically is a Hash with method-like access.
#
# @example
# CommentIndex.search("hello world").results
# # => [#<SearchFlip::Result ...>, ...]
#
# @return [Array] An array of results
def results
- @results ||= hits["hits"].map { |hit| Result.from_hit(hit) }
+ @results ||= hits["hits"].map { |hit| SearchFlip::Result.from_hit(hit) }
end
# Returns the named sugggetion, if a name is specified or alle suggestions.
#
# @example
@@ -222,11 +221,11 @@
#
# @return [Array] An array of database records
def records
@records ||= begin
- sort_map = ids.each_with_index.with_object({}) { |(id, index), hash| hash[id.to_s] = index }
+ sort_map = ids.each_with_index.each_with_object({}) { |(id, index), hash| hash[id.to_s] = index }
scope.to_a.sort_by { |record| sort_map[criteria.target.record_id(record).to_s] }
end
end
@@ -302,16 +301,16 @@
return @aggregations[key] if @aggregations.key?(key)
@aggregations[key] =
if response["aggregations"].nil? || response["aggregations"][key].nil?
- Result.new
+ SearchFlip::Result.new
elsif response["aggregations"][key]["buckets"].is_a?(Array)
- response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = Result.new(bucket) }
+ response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = SearchFlip::Result.convert(bucket) }
elsif response["aggregations"][key]["buckets"].is_a?(Hash)
- Result.new response["aggregations"][key]["buckets"]
+ SearchFlip::Result.convert(response["aggregations"][key]["buckets"])
else
- Result.new response["aggregations"][key]
+ SearchFlip::Result.convert(response["aggregations"][key])
end
end
end
end