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, wildcard

Constructor Details

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

Returns a new instance of BooleanQuery.

Yield Parameters:

[View source]

823
824
825
826
827
828
829
# File 'lib/couchbase/search_options.rb', line 823

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)

817
818
819
# File 'lib/couchbase/search_options.rb', line 817

def boost
  @boost
end

#operatornil, ...

Returns:

  • (nil, :or, :and)

820
821
822
# File 'lib/couchbase/search_options.rb', line 820

def operator
  @operator
end

Instance Method Details

#must(*queries) ⇒ Object

Parameters:

[View source]

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

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

#must_not(*queries) ⇒ Object

Parameters:

[View source]

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

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

#should(*queries) ⇒ Object

Parameters:

[View source]

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

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

#should_min(min) ⇒ Object

Parameters:

  • min (Integer)

    minimal value for “should” disjunction query

[View source]

832
833
834
835
# File 'lib/couchbase/search_options.rb', line 832

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

#to_json(*args) ⇒ String

Returns:

  • (String)
[View source]

856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/couchbase/search_options.rb', line 856

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["operator"] = operator.to_s if operator
  data.to_json(*args)
end