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

Inherits:
Couchbase::Cluster::SearchQuery show all
Defined in:
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

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:



761
762
763
764
765
766
767
# File 'lib/couchbase/search_options.rb', line 761

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)


758
759
760
# File 'lib/couchbase/search_options.rb', line 758

def boost
  @boost
end

Instance Method Details

#must(*queries) ⇒ Object

Parameters:



776
777
778
779
# File 'lib/couchbase/search_options.rb', line 776

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

#must_not(*queries) ⇒ Object

Parameters:



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

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

#should(*queries) ⇒ Object

Parameters:



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

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

#should_min(min) ⇒ Object

Parameters:

  • min (Integer)

    minimal value for “should” disjunction query



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

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

#to_json(*args) ⇒ String

Returns:

  • (String)


794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/couchbase/search_options.rb', line 794

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