Class: Couchbase::Cluster::SearchQuery::NumericRangeQuery

Inherits:
Couchbase::Cluster::SearchQuery show all
Defined in:
lib/couchbase/search_options.rb

Overview

The numeric range query finds documents containing a numeric value in the specified field within the specified range.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Couchbase::Cluster::SearchQuery

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

Constructor Details

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

Returns a new instance of NumericRangeQuery.

Yield Parameters:

[View source]

407
408
409
410
411
412
413
414
# File 'lib/couchbase/search_options.rb', line 407

def initialize
  super
  @min = nil
  @min_inclusive = nil
  @max = nil
  @max_inclusive = nil
  yield self if block_given?
end

Instance Attribute Details

#boostFloat

Returns:

  • (Float)

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

def boost
  @boost
end

#fieldString

Returns:

  • (String)

382
383
384
# File 'lib/couchbase/search_options.rb', line 382

def field
  @field
end

Instance Method Details

#max(upper_bound, inclusive = nil) ⇒ Object

Sets upper bound of the range.

The upper boundary is considered exclusive by default on the server side.

Parameters:

  • upper_bound (Numeric)
  • inclusive (Boolean) (defaults to: nil)
[View source]

401
402
403
404
# File 'lib/couchbase/search_options.rb', line 401

def max(upper_bound, inclusive = nil)
  @max = upper_bound
  @max_inclusive = inclusive
end

#min(lower_bound, inclusive = nil) ⇒ Object

Sets lower bound of the range.

The lower boundary is considered inclusive by default on the server side.

Parameters:

  • lower_bound (Numeric)
  • inclusive (Boolean) (defaults to: nil)
[View source]

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

def min(lower_bound, inclusive = nil)
  @min = lower_bound
  @min_inclusive = inclusive
end

#to_json(*args) ⇒ String

Returns:

  • (String)
[View source]

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/couchbase/search_options.rb', line 417

def to_json(*args)
  if @min.nil? && @max.nil?
    raise ArgumentError, "either min or max must be set for NumericRangeQuery"
  end

  data = {}
  data["boost"] = boost if boost
  data["field"] = field if field
  if @min
    data["min"] = @min
    data["inclusive_min"] = @min_inclusive unless @min_inclusive.nil?
  end
  if @max
    data["max"] = @max
    data["inclusive_max"] = @max_inclusive unless @max_inclusive.nil?
  end
  data.to_json(*args)
end