class Queries::RangeQueryBuilder
Constants
- NAME
Public Class Methods
new(field_name: @field_name = field_name)
click to toggle source
params:
@gt: Greater-than @gte: Greater-than or equal to @lt: Less-than @lte: Less-than or equal to @format: Formatted dates will be parsed using the format specified on the date field by default, but it can be overridden by passing the format parameter to the range query @time_zone: Dates can be converted from another timezone to UTC either by specifying the time zone in the date value itself (if the format accepts it), or it can be specified as the time_zone parameter @relation: range queries can be used on fields of type range, allowing to match a range specified in the query with a range field value in the document. The relation parameter controls how these two ranges are matched: WITHIN Matches documents who’s range field is entirely within the query’s range. CONTAINS Matches documents who’s range field entirely contains the query’s range. INTERSECTS Matches documents who’s range field intersects the query’s range. This is the default value when querying range fields.
Date math and rounding
When using date math to round dates to the nearest day, month, hour, etc, the rounded dates depend on whether the ends of the ranges are inclusive or exclusive.Rounding up moves to the last millisecond of the rounding scope, and rounding down to the first millisecond of the rounding scope. For example: gt Greater than the date rounded up: 2014-11-18||/M becomes 2014-11-30T23:59:59.999, ie excluding the entire month. gte Greater than or equal to the date rounded down: 2014-11-18||/M becomes 2014-11-01, ie including the entire month. lt Less than the date rounded down: 2014-11-18||/M becomes 2014-11-01, ie excluding the entire month. lte Less than or equal to the date rounded up: 2014-11-18||/M becomes 2014-11-30T23:59:59.999, ie including the entire month.
# File lib/queries/range_query_builder.rb, line 42 def initialize field_name: @field_name = field_name @gt= nil @gte= nil @lt= nil @lte= nil @format= nil @time_zone = nil @relation= nil end
Public Instance Methods
field_name_expr()
click to toggle source
returns field_name
# File lib/queries/range_query_builder.rb, line 70 def field_name_expr return @field_name end
format(value)
click to toggle source
sets format
# File lib/queries/range_query_builder.rb, line 124 def format value @format = value return self end
format_expr()
click to toggle source
Format ##########
returns format
# File lib/queries/range_query_builder.rb, line 120 def format_expr return @format end
gt(value)
click to toggle source
sets gt
# File lib/queries/range_query_builder.rb, line 80 def gt value @gt = value return self end
gt_expr()
click to toggle source
Greater Than ##########
returns gt
# File lib/queries/range_query_builder.rb, line 76 def gt_expr return @gt end
gte(value)
click to toggle source
sets gte
# File lib/queries/range_query_builder.rb, line 91 def gte value @gte = value return self end
gte_expr()
click to toggle source
Greater Than Or Equal To ##########
returns gte
# File lib/queries/range_query_builder.rb, line 87 def gte_expr return @gte end
lt(value)
click to toggle source
sets lt
# File lib/queries/range_query_builder.rb, line 102 def lt value @lt = value return self end
lt_expr()
click to toggle source
Less Than ##########
return lt
# File lib/queries/range_query_builder.rb, line 98 def lt_expr return @lt end
lte(value)
click to toggle source
sets lte
# File lib/queries/range_query_builder.rb, line 113 def lte value @lte = value return self end
lte_expr()
click to toggle source
Less Than Or Equal To ##########
returns lte
# File lib/queries/range_query_builder.rb, line 109 def lte_expr return @lte end
query()
click to toggle source
# File lib/queries/range_query_builder.rb, line 53 def query query = {} range_query = {} field_options = self.common_query field_options[:gt] = @gt if @gt.present? field_options[:gte] = @gte if @gte.present? field_options[:lt] = @lt if @lt.present? field_options[:lte] = @lte if @lte.present? field_options[:format] = @format if @format.present? field_options[:time_zone] = @time_zone if @time_zone.present? field_options[:relation] = @relation if @relation.present? range_query[@field_name.intern] = field_options query[name.intern] = range_query return query end
relation(shape_relation)
click to toggle source
sets relation, input: ShapeRelation object
# File lib/queries/range_query_builder.rb, line 146 def relation shape_relation @relation = shape_relation.relation return self end
relation_expr()
click to toggle source
RANGE RELATION ##########
returns relation
# File lib/queries/range_query_builder.rb, line 142 def relation_expr return @relation end
time_zone(value)
click to toggle source
sets time_zone
# File lib/queries/range_query_builder.rb, line 135 def time_zone value @time_zone = value return self end
time_zone_expr()
click to toggle source
Time Zone ##########
returns time_zone
# File lib/queries/range_query_builder.rb, line 131 def time_zone_expr return @time_zone end