Class: Couchbase::SearchQuery::DateRangeQuery

Inherits:
Couchbase::SearchQuery show all
Defined in:
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".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Couchbase::SearchQuery

boolean_field, booleans, conjuncts, date_range, disjuncts, doc_id, geo_bounding_box, geo_distance, geo_polygon, match, match_all, match_none, match_phrase, numeric_range, phrase, prefix, query_string, regexp, term, term_range, #to_json, wildcard

Constructor Details

#initialize {|self| ... } ⇒ DateRangeQuery

Returns a new instance of DateRangeQuery.

Yield Parameters:



396
397
398
399
400
401
402
403
# File 'lib/couchbase/search_options.rb', line 396

def initialize
  super
  @start_time = nil
  @start_inclusive = nil
  @end_time = nil
  @end_inclusive = nil
  yield self if block_given?
end

Instance Attribute Details

#boostFloat

Returns:

  • (Float)


364
365
366
# File 'lib/couchbase/search_options.rb', line 364

def boost
  @boost
end

#date_time_parserString

Returns:

  • (String)


370
371
372
# File 'lib/couchbase/search_options.rb', line 370

def date_time_parser
  @date_time_parser
end

#fieldString

Returns:

  • (String)


367
368
369
# File 'lib/couchbase/search_options.rb', line 367

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.

Parameters:

  • time_point (Time, String)

    end time. When Time object is passed #date_time_parser must be nil (to use server default)

  • inclusive (Boolean) (defaults to: nil)


390
391
392
393
# File 'lib/couchbase/search_options.rb', line 390

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.

Parameters:

  • time_point (Time, String)

    start time. When Time object is passed #date_time_parser must be nil (to use server default)

  • inclusive (Boolean) (defaults to: nil)


379
380
381
382
# File 'lib/couchbase/search_options.rb', line 379

def start_time(time_point, inclusive = nil)
  @start_time = time_point
  @start_inclusive = inclusive
end

#to_hHash<Symbol, #to_json>

Returns:

Raises:

  • (ArgumentError)


408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/couchbase/search_options.rb', line 408

def to_h
  raise ArgumentError, "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