Class: Couchbase::Cluster::SearchQuery::BooleanQuery

Inherits:
Couchbase::Cluster::SearchQuery show all
Defined in:
lib/couchbase/search_options.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/search_options.rb
more...

Overview

The boolean query is a useful combination of conjunction and disjunction 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, #to_json, wildcard

Constructor Details

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

Returns a new instance of BooleanQuery.

Yield Parameters:

[View source]

770
771
772
773
774
775
776
# File 'lib/couchbase/search_options.rb', line 770

def initialize
  super()
  @must = ConjunctionQuery.new
  @must_not = DisjunctionQuery.new
  @should = DisjunctionQuery.new
  yield self if block_given?
end

Instance Attribute Details

#boostFloat

Returns:

  • (Float)

767
768
769
# File 'lib/couchbase/search_options.rb', line 767

def boost
  @boost
end

Instance Method Details

#must(*queries) ⇒ Object

Parameters:

[View source]

785
786
787
788
# File 'lib/couchbase/search_options.rb', line 785

def must(*queries)
  @must.and_also(*queries)
  self
end

#must_not(*queries) ⇒ Object

Parameters:

[View source]

791
792
793
794
# File 'lib/couchbase/search_options.rb', line 791

def must_not(*queries)
  @must_not.or_else(*queries)
  self
end

#should(*queries) ⇒ Object

Parameters:

[View source]

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

def should(*queries)
  @should.or_else(*queries)
  self
end

#should_min(min) ⇒ Object

Parameters:

  • min (Integer)

    minimal value for “should” disjunction query

[View source]

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

def should_min(min)
  @should.min = min
  self
end

#to_hHash<Symbol, #to_json>

Returns:

[View source]

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

def to_h
  if @must.empty? && @must_not.empty? && @should.empty?
    raise ArgumentError, "BooleanQuery must have at least one non-empty sub-query"
  end

  data = {}
  data[:must] = @must.to_h unless @must.empty?
  data[:must_not] = @must_not.to_h unless @must_not.empty?
  data[:should] = @should.to_h unless @should.empty?
  data[:boost] = boost if boost
  data
end