Class: Stretchy::Queries::BoolQuery
- Defined in:
- lib/stretchy/queries/bool_query.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BoolQuery
constructor
A new instance of BoolQuery.
- #to_search ⇒ Object
Methods included from Utils::Validation
#errors, included, #json_attributes, #require_one!, #require_only_one!, #valid?, #validate!, #validator
Constructor Details
#initialize(options = {}) ⇒ BoolQuery
Returns a new instance of BoolQuery.
17 18 19 20 21 22 23 |
# File 'lib/stretchy/queries/bool_query.rb', line 17 def initialize( = {}) @must = Array([:must]) @must_not = Array([:must_not]) @should = Array([:should]) require_one! :must, :must_not, :should validate! end |
Instance Method Details
#to_search ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/stretchy/queries/bool_query.rb', line 25 def to_search json = {} json[:must] = @must.map(&:to_search) if @must.any? json[:must_not] = @must_not.map(&:to_search) if @must_not.any? json[:should] = @should.map(&:to_search) if @should.any? { bool: json } end |