Class: ElasticsearchDslBuilder::DSL::Search::Queries::Bool
- Defined in:
- lib/elasticsearch_dsl_builder/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 Attribute Summary
Attributes inherited from Query
Instance Method Summary collapse
- #filter(query) ⇒ Object
-
#initialize ⇒ Bool
constructor
class variables @minimum_should_match, @must, @must_not, @should, @filter.
- #minimum_should_match(value) ⇒ Object
- #must(query) ⇒ Object
- #must_not(query) ⇒ Object
- #should(query) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Bool
class variables @minimum_should_match, @must, @must_not, @should, @filter
13 14 15 16 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 13 def initialize @type = :bool super() end |
Instance Method Details
#filter(query) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 51 def filter(query) raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query) @filter ||= [] hashed_query = query @filter << hashed_query unless @filter.include?(hashed_query) self end |
#minimum_should_match(value) ⇒ Object
18 19 20 21 22 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 18 def minimum_should_match(value) raise ArgumentError, 'minimum_should_match must be Numeric' unless value.is_a?(Numeric) @minimum_should_match = value self end |
#must(query) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 24 def must(query) raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query) @must ||= [] hashed_query = query @must << hashed_query unless @must.include?(hashed_query) self end |
#must_not(query) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 33 def must_not(query) raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query) @must_not ||= [] hashed_query = query @must_not << hashed_query unless @must_not.include?(hashed_query) self end |
#should(query) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 42 def should(query) raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query) @should ||= [] hashed_query = query @should << hashed_query unless @should.include?(hashed_query) self end |
#to_hash ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb', line 60 def to_hash @query = {} @query.update(minimum_should_match: @minimum_should_match) if @minimum_should_match @query.update(must: @must.map(&:to_hash)) if @must @query.update(must_not: @must_not.map(&:to_hash)) if @must_not @query.update(should: @should.map(&:to_hash)) if @should @query.update(filter: @filter.map(&:to_hash)) if @filter super end |