Class: Couchbase::SearchQuery::DateRangeQuery
- Inherits:
-
SearchQuery
- Object
- SearchQuery
- Couchbase::SearchQuery::DateRangeQuery
- Defined in:
- lib/couchbase/search_options.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/search_options.rb
Overview
The date range query finds documents containing a date value in the specified field within the specified range.
Constant Summary collapse
- DATE_FORMAT_RFC3339 =
"%Y-%m-%dT%H:%M:%S%:z"
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#end_time(time_point, inclusive = nil) ⇒ Object
Sets the upper boundary of the range.
-
#initialize {|self| ... } ⇒ DateRangeQuery
constructor
A new instance of DateRangeQuery.
-
#start_time(time_point, inclusive = nil) ⇒ Object
Sets the lower boundary of the range.
- #to_h ⇒ Hash<Symbol, #to_json>
Constructor Details
#initialize {|self| ... } ⇒ DateRangeQuery
Returns a new instance of DateRangeQuery.
394 395 396 397 398 399 400 401 |
# File 'lib/couchbase/search_options.rb', line 394 def initialize super @start_time = nil @start_inclusive = nil @end_time = nil @end_inclusive = nil yield self if block_given? end |
Instance Attribute Details
#boost ⇒ Float
362 363 364 |
# File 'lib/couchbase/search_options.rb', line 362 def boost @boost end |
#date_time_parser ⇒ String
368 369 370 |
# File 'lib/couchbase/search_options.rb', line 368 def date_time_parser @date_time_parser end |
#field ⇒ String
365 366 367 |
# File 'lib/couchbase/search_options.rb', line 365 def field @field end |
Instance Method Details
#end_time(time_point, inclusive = nil) ⇒ Object
Note:
The upper boundary is considered exclusive by default on the server side.
Sets the upper boundary of the range.
388 389 390 391 |
# File 'lib/couchbase/search_options.rb', line 388 def end_time(time_point, inclusive = nil) @end_time = time_point @end_inclusive = inclusive end |
#start_time(time_point, inclusive = nil) ⇒ Object
Note:
The lower boundary is considered inclusive by default on the server side.
Sets the lower boundary of the range.
377 378 379 380 |
# File 'lib/couchbase/search_options.rb', line 377 def start_time(time_point, inclusive = nil) @start_time = time_point @start_inclusive = inclusive end |
#to_h ⇒ Hash<Symbol, #to_json>
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/couchbase/search_options.rb', line 406 def to_h raise Error::InvalidArgument, "either start_time or end_time must be set for DateRangeQuery" if @start_time.nil? && @end_time.nil? data = {} data[:boost] = boost if boost data[:field] = field if field data[:datetime_parser] = date_time_parser if date_time_parser if @start_time data[:start] = if @start_time.respond_to?(:strftime) @start_time.strftime(DATE_FORMAT_RFC3339) else @start_time end data[:inclusive_start] = @start_inclusive unless @start_inclusive.nil? end if @end_time data[:end] = if @end_time.respond_to?(:strftime) @end_time.strftime(DATE_FORMAT_RFC3339) else @end_time end data[:inclusive_end] = @end_inclusive unless @end_inclusive.nil? end data end |