Class: Elasticsearch::DSL::Search::Queries::Bool
- Inherits:
-
Object
- Object
- Elasticsearch::DSL::Search::Queries::Bool
- Includes:
- BaseComponent
- Defined in:
- lib/elasticsearch/dsl/search/queries/bool.rb
Overview
A compound query which matches documents based on combinations of queries
See the integration test for a working example.
Instance Method Summary collapse
- #filter(*args, &block) ⇒ Object
- #must(*args, &block) ⇒ Object
- #must_not(*args, &block) ⇒ Object
- #should(*args, &block) ⇒ Object
- #to_hash ⇒ Object
Methods included from BaseComponent
Instance Method Details
#filter(*args, &block) ⇒ Object
60 61 62 63 |
# File 'lib/elasticsearch/dsl/search/queries/bool.rb', line 60 def filter(*args, &block) @filter = block ? Filter.new(*args, &block) : args.first self end |
#must(*args, &block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/elasticsearch/dsl/search/queries/bool.rb', line 39 def must(*args, &block) @hash[name][:must] ||= [] value = Query.new(*args, &block).to_hash @hash[name][:must].push(value).flatten! unless @hash[name][:must].include?(value) self end |
#must_not(*args, &block) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/elasticsearch/dsl/search/queries/bool.rb', line 46 def must_not(*args, &block) @hash[name][:must_not] ||= [] value = Query.new(*args, &block).to_hash @hash[name][:must_not].push(value).flatten! unless @hash[name][:must_not].include?(value) self end |
#should(*args, &block) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/elasticsearch/dsl/search/queries/bool.rb', line 53 def should(*args, &block) @hash[name][:should] ||= [] value = Query.new(*args, &block).to_hash @hash[name][:should].push(value).flatten! unless @hash[name][:should].include?(value) self end |
#to_hash ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/elasticsearch/dsl/search/queries/bool.rb', line 65 def to_hash @hash[name].update(@args.to_hash) if @args.respond_to?(:to_hash) if @block call else @hash[name] = @args unless @args.nil? || @args.empty? end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter @hash[name].update(filter: _filter) end @hash end |