From 3853d438a11e45225060ddd48b76eec66fc52d0e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 13 Feb 2014 00:57:34 -0800 Subject: [PATCH] Do not mutate options --- lib/searchkick/search.rb | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/searchkick/search.rb b/lib/searchkick/search.rb index 51ba7b3..6ab0413 100644 --- a/lib/searchkick/search.rb +++ b/lib/searchkick/search.rb @@ -224,30 +224,29 @@ module Searchkick end if value.is_a?(Hash) - if value[:near] - filters << { - geo_distance: { - field => value.delete(:near).map(&:to_f).reverse, - distance: value.delete(:within) || "50mi" + value.each do |op, op_value| + case op + when :within, :bottom_right + # do nothing + when :near + filters << { + geo_distance: { + field => op_value.map(&:to_f).reverse, + distance: value[:within] || "50mi" + } } - } - end - - if value[:top_left] - filters << { - geo_bounding_box: { - field => { - top_left: value.delete(:top_left).map(&:to_f).reverse, - bottom_right: value.delete(:bottom_right).map(&:to_f).reverse + when :top_left + filters << { + geo_bounding_box: { + field => { + top_left: op_value.map(&:to_f).reverse, + bottom_right: value[:bottom_right].map(&:to_f).reverse + } } } - } - end - - value.each do |op, op_value| - if op == :not # not equal + when :not # not equal filters << {not: term_filters.call(field, op_value)} - elsif op == :all + when :all filters << {terms: {field => op_value, execution: "and"}} else range_query = -- libgit2 0.21.0