Class: OpenSearch::DSL::Search::Queries::Bool
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Queries::Bool
- Includes:
- BaseComponent
- Defined in:
- lib/opensearch/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
89 90 91 92 93 94 95 |
# File 'lib/opensearch/dsl/search/queries/bool.rb', line 89 def filter(*args, &block) @hash[name][:filter] ||= [] if filter = block ? Filter.new(*args, &block) : args.first @hash[name][:filter] << filter.to_hash end self end |
#must(*args, &block) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/opensearch/dsl/search/queries/bool.rb', line 68 def must(*args, &block) @hash[name][:must] ||= [] value = args.empty? ? Query.new(*args, &block).to_hash : args.first.to_hash @hash[name][:must].push(value).flatten! unless @hash[name][:must].include?(value) self end |
#must_not(*args, &block) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/opensearch/dsl/search/queries/bool.rb', line 75 def must_not(*args, &block) @hash[name][:must_not] ||= [] value = args.empty? ? Query.new(*args, &block).to_hash : args.first.to_hash @hash[name][:must_not].push(value).flatten! unless @hash[name][:must_not].include?(value) self end |
#should(*args, &block) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/opensearch/dsl/search/queries/bool.rb', line 82 def should(*args, &block) @hash[name][:should] ||= [] value = args.empty? ? Query.new(*args, &block).to_hash : args.first.to_hash @hash[name][:should].push(value).flatten! unless @hash[name][:should].include?(value) self end |
#to_hash ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/opensearch/dsl/search/queries/bool.rb', line 97 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 @hash end |