Class: Redis::Commands::Search::NumericField
- Defined in:
- lib/redis/commands/modules/search/field.rb
Overview
A NUMERIC field, indexing numeric values for range queries.
Instance Attribute Summary
Attributes inherited from Field
#alias_name, #name, #options, #query, #type
Instance Method Summary collapse
-
#between(min, max) ⇒ Query
Add an inclusive range predicate to the bound query.
-
#gt(value) ⇒ Query
Add a greater-than range predicate to the bound query.
-
#initialize(name, query = nil, **options) ⇒ NumericField
constructor
Build a
NUMERICfield. -
#lt(value) ⇒ Query
Add a less-than range predicate to the bound query.
Methods inherited from Field
Constructor Details
#initialize(name, query = nil, **options) ⇒ NumericField
Build a NUMERIC field.
144 145 146 |
# File 'lib/redis/commands/modules/search/field.rb', line 144 def initialize(name, query = nil, **) super(name, :numeric, query, **) end |
Instance Method Details
#between(min, max) ⇒ Query
Add an inclusive range predicate to the bound query.
172 173 174 175 176 |
# File 'lib/redis/commands/modules/search/field.rb', line 172 def between(min, max) # Coerce to numeric so a value can't inject range/query syntax. RangePredicate renders # bounds verbatim, so the field boundary is where untrusted input must be validated. query.add_predicate(RangePredicate.new(@alias_name || name, Float(min), Float(max))) end |
#gt(value) ⇒ Query
Add a greater-than range predicate to the bound query.
153 154 155 |
# File 'lib/redis/commands/modules/search/field.rb', line 153 def gt(value) query.add_predicate(RangePredicate.new(@alias_name || name, "(#{Float(value)}", "+inf")) end |
#lt(value) ⇒ Query
Add a less-than range predicate to the bound query.
162 163 164 |
# File 'lib/redis/commands/modules/search/field.rb', line 162 def lt(value) query.add_predicate(RangePredicate.new(@alias_name || name, "-inf", "(#{Float(value)}")) end |