Method: Springy::Factory.params_to_filters

Defined in:
lib/springy/factory.rb

.params_to_filters(params, context = default_context) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/springy/factory.rb', line 102

def params_to_filters(params, context = default_context)
  params.map do |field, val|
    case val
    when Range
      Node.new({range: {field => {gte: val.min, lte: val.max}}}, context)
    when nil
      nil_ctx = context.merge(must_not: true)
      Node.new({exists: {field: field}}, nil_ctx)
    when Hash
      nested(val, field, context)
    else
      Node.new({terms: {field => Array(val)}}, context)
    end
  end
end