Class: Couchbase::SearchQuery::DisjunctionQuery

Inherits:
Couchbase::SearchQuery show all
Defined in:
lib/couchbase/search_options.rb,
/code/couchbase-ruby-client/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::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(*queries) {|self| ... } ⇒ DisjunctionQuery

Returns a new instance of DisjunctionQuery.

Parameters:

Yield Parameters:



787
788
789
790
791
# File 'lib/couchbase/search_options.rb', line 787

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

Instance Attribute Details

#boostFloat

Returns:

  • (Float)


779
780
781
# File 'lib/couchbase/search_options.rb', line 779

def boost
  @boost
end

#minInteger

Returns:

  • (Integer)


782
783
784
# File 'lib/couchbase/search_options.rb', line 782

def min
  @min
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


798
799
800
# File 'lib/couchbase/search_options.rb', line 798

def empty?
  @queries.empty?
end

#or_else(*queries) ⇒ Object

Parameters:



794
795
796
# File 'lib/couchbase/search_options.rb', line 794

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

#to_hHash<Symbol, #to_json>

Returns:

Raises:



803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/couchbase/search_options.rb', line 803

def to_h
  raise Error::InvalidArgument, "compound disjunction query must have sub-queries" if @queries.nil? || @queries.empty?

  data = {:disjuncts => @queries.uniq.map(&:to_h)}
  if min
    raise Error::InvalidArgument, "disjunction query has fewer sub-queries than configured minimum" if @queries.size < min

    data[:min] = min
  end
  data[:boost] = boost if boost
  data
end