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

Constructor Details

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

Returns a new instance of BooleanQuery.

Yield Parameters:

[View source]

703
704
705
706
707
708
709
# File 'lib/couchbase/search_options.rb', line 703

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)

700
701
702
# File 'lib/couchbase/search_options.rb', line 700

def boost
  @boost
end

Instance Method Details

#must(*queries) ⇒ Object

Parameters:

[View source]

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

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

#must_not(*queries) ⇒ Object

Parameters:

[View source]

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

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

#should(*queries) ⇒ Object

Parameters:

[View source]

730
731
732
733
# File 'lib/couchbase/search_options.rb', line 730

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

#should_min(min) ⇒ Object

Parameters:

  • min (Integer)

    minimal value for “should” disjunction query

[View source]

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

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

#to_json(*args) ⇒ String

Returns:

  • (String)
[View source]

736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/couchbase/search_options.rb', line 736

def to_json(*args)
  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 unless @must.empty?
  data["must_not"] = @must_not unless @must_not.empty?
  data["should"] = @should unless @should.empty?
  data["boost"] = boost if boost
  data.to_json(*args)
end