Class: Couchbase::SearchQuery::BooleanQuery

Inherits:
SearchQuery
  • Object
show all
Defined in:
lib/couchbase/search_options.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/search_options.rb

Overview

The boolean query is a useful combination of conjunction and disjunction queries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BooleanQuery.

Yield Parameters:



828
829
830
831
832
833
834
# File 'lib/couchbase/search_options.rb', line 828

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

Instance Attribute Details

#boost ⇒ Float

Returns:

  • (Float)


825
826
827
# File 'lib/couchbase/search_options.rb', line 825

def boost
  @boost
end

Instance Method Details

#must(*queries) ⇒ Object

Parameters:



843
844
845
846
# File 'lib/couchbase/search_options.rb', line 843

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

#must_not(*queries) ⇒ Object

Parameters:



849
850
851
852
# File 'lib/couchbase/search_options.rb', line 849

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

#should(*queries) ⇒ Object

Parameters:



855
856
857
858
# File 'lib/couchbase/search_options.rb', line 855

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

#should_min(min) ⇒ Object

Parameters:

  • min (Integer) —

    minimal value for "should" disjunction query



837
838
839
840
# File 'lib/couchbase/search_options.rb', line 837

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

#to_h ⇒ Hash<Symbol, #to_json>

Returns:



861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/couchbase/search_options.rb', line 861

def to_h
  if @must.empty? && @must_not.empty? && @should.empty?
    raise Error::InvalidArgument,
          "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