Class: Queries::RangeQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- Queries::RangeQueryBuilder
- Defined in:
- lib/queries/range_query_builder.rb
Constant Summary collapse
- NAME =
"range"
Instance Method Summary collapse
-
#field_name_expr ⇒ Object
returns field_name.
-
#format(value) ⇒ Object
sets format.
-
#format_expr ⇒ Object
Format ########## returns format.
-
#gt(value) ⇒ Object
sets gt.
-
#gt_expr ⇒ Object
Greater Than ########## returns gt.
-
#gte(value) ⇒ Object
sets gte.
-
#gte_expr ⇒ Object
Greater Than Or Equal To ########## returns gte.
-
#initialize(field_name:) ⇒ RangeQueryBuilder
constructor
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.
-
#lt(value) ⇒ Object
sets lt.
-
#lt_expr ⇒ Object
Less Than ########## return lt.
-
#lte(value) ⇒ Object
sets lte.
-
#lte_expr ⇒ Object
Less Than Or Equal To ########## returns lte.
- #query ⇒ Object
-
#relation(shape_relation) ⇒ Object
sets relation, input: ShapeRelation object.
-
#relation_expr ⇒ Object
RANGE RELATION ########## returns relation.
-
#time_zone(value) ⇒ Object
sets time_zone.
-
#time_zone_expr ⇒ Object
Time Zone ########## returns time_zone.
Methods inherited from QueryBuilder
Methods included from AttributesReader
Methods included from AbstractQueryBuilder
Constructor Details
#initialize(field_name:) ⇒ RangeQueryBuilder
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.
42 43 44 45 46 47 48 49 50 51 |
# 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 |
Instance Method Details
#field_name_expr ⇒ Object
returns field_name
70 71 72 |
# File 'lib/queries/range_query_builder.rb', line 70 def field_name_expr return @field_name end |
#format(value) ⇒ Object
sets format
124 125 126 127 |
# File 'lib/queries/range_query_builder.rb', line 124 def format value @format = value return self end |
#format_expr ⇒ Object
Format ########## returns format
120 121 122 |
# File 'lib/queries/range_query_builder.rb', line 120 def format_expr return @format end |
#gt(value) ⇒ Object
sets gt
80 81 82 83 |
# File 'lib/queries/range_query_builder.rb', line 80 def gt value @gt = value return self end |
#gt_expr ⇒ Object
Greater Than ########## returns gt
76 77 78 |
# File 'lib/queries/range_query_builder.rb', line 76 def gt_expr return @gt end |
#gte(value) ⇒ Object
sets gte
91 92 93 94 |
# File 'lib/queries/range_query_builder.rb', line 91 def gte value @gte = value return self end |
#gte_expr ⇒ Object
Greater Than Or Equal To ########## returns gte
87 88 89 |
# File 'lib/queries/range_query_builder.rb', line 87 def gte_expr return @gte end |
#lt(value) ⇒ Object
sets lt
102 103 104 105 |
# File 'lib/queries/range_query_builder.rb', line 102 def lt value @lt = value return self end |
#lt_expr ⇒ Object
Less Than ########## return lt
98 99 100 |
# File 'lib/queries/range_query_builder.rb', line 98 def lt_expr return @lt end |
#lte(value) ⇒ Object
sets lte
113 114 115 116 |
# File 'lib/queries/range_query_builder.rb', line 113 def lte value @lte = value return self end |
#lte_expr ⇒ Object
Less Than Or Equal To ########## returns lte
109 110 111 |
# File 'lib/queries/range_query_builder.rb', line 109 def lte_expr return @lte end |
#query ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/queries/range_query_builder.rb', line 53 def query query = {} range_query = {} = self.common_query [:gt] = @gt if @gt.present? [:gte] = @gte if @gte.present? [:lt] = @lt if @lt.present? [:lte] = @lte if @lte.present? [:format] = @format if @format.present? [:time_zone] = @time_zone if @time_zone.present? [:relation] = @relation if @relation.present? range_query[@field_name.intern] = query[name.intern] = range_query return query end |
#relation(shape_relation) ⇒ Object
sets relation, input: ShapeRelation object
146 147 148 149 |
# File 'lib/queries/range_query_builder.rb', line 146 def relation shape_relation @relation = shape_relation.relation return self end |
#relation_expr ⇒ Object
RANGE RELATION ########## returns relation
142 143 144 |
# File 'lib/queries/range_query_builder.rb', line 142 def relation_expr return @relation end |
#time_zone(value) ⇒ Object
sets time_zone
135 136 137 138 |
# File 'lib/queries/range_query_builder.rb', line 135 def time_zone value @time_zone = value return self end |
#time_zone_expr ⇒ Object
Time Zone ########## returns time_zone
131 132 133 |
# File 'lib/queries/range_query_builder.rb', line 131 def time_zone_expr return @time_zone end |