Class: Couchbase::Cluster::SearchQuery::DisjunctionQuery

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

Overview

Result documents must satisfy a configurable min number of child queries.

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, geo_polygon, match, match_all, match_none, match_phrase, numeric_range, phrase, prefix, query_string, regexp, term, term_range, wildcard

Constructor Details

#initialize(*queries) {|self| ... } ⇒ DisjunctionQuery

Returns a new instance of DisjunctionQuery.

Parameters:

Yield Parameters:



716
717
718
719
720
# File 'lib/couchbase/search_options.rb', line 716

def initialize(*queries)
  super()
  @queries = queries.flatten
  yield self if block_given?
end

Instance Attribute Details

#boostFloat

Returns:

  • (Float)


708
709
710
# File 'lib/couchbase/search_options.rb', line 708

def boost
  @boost
end

#minInteger

Returns:

  • (Integer)


711
712
713
# File 'lib/couchbase/search_options.rb', line 711

def min
  @min
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


727
728
729
# File 'lib/couchbase/search_options.rb', line 727

def empty?
  @queries.empty?
end

#or_else(*queries) ⇒ Object

Parameters:



723
724
725
# File 'lib/couchbase/search_options.rb', line 723

def or_else(*queries)
  @queries |= queries.flatten
end

#to_json(*args) ⇒ String

Returns:

  • (String)

Raises:

  • (ArgumentError)


732
733
734
735
736
737
738
739
740
741
742
743
# File 'lib/couchbase/search_options.rb', line 732

def to_json(*args)
  raise ArgumentError, "compound disjunction query must have sub-queries" if @queries.nil? || @queries.empty?

  data = {"disjuncts" => @queries.uniq}
  if min
    raise ArgumentError, "disjunction query has fewer sub-queries than configured minimum" if @queries.size < min

    data["min"] = min
  end
  data["boost"] = boost if boost
  data.to_json(*args)
end