Sha256: c5d2bfe92ea9bec297130f1a67e6d591a1cba294759fa3a71b935cd5870d0b30
Contents?: true
Size: 1.91 KB
Versions: 3
Compression:
Stored size: 1.91 KB
Contents
module SearchFlip # The SearchFlip::Aggregation class puts together everything # required to use the ElasticSearch aggregation framework via mixins and # adds a method to convert it to a hash format to be used in the request. class Aggregation include SearchFlip::Filterable include SearchFlip::Aggregatable attr_reader :target def initialize(target:) @target = target end # @api private # # Converts the aggregation to a hash format that can be used in the request. # # @return [Hash] A hash version of the aggregation def to_hash res = {} res[:aggregations] = aggregation_values if aggregation_values if must_values || search_values || must_not_values || should_values || filter_values if target.connection.version.to_i >= 2 res[:filter] = { bool: {} .merge(must_values || search_values ? { must: (must_values || []) + (search_values || []) } : {}) .merge(must_not_values ? { must_not: must_not_values } : {}) .merge(should_values ? { should: should_values } : {}) .merge(filter_values ? { filter: filter_values } : {}) } else filters = (filter_values || []) + (must_not_values || []).map { |must_not_value| { not: must_not_value } } queries = {} .merge(must_values || search_values ? { must: (must_values || []) + (search_values || []) } : {}) .merge(should_values ? { should: should_values } : {}) filters_and_queries = filters + (queries.size > 0 ? [bool: queries] : []) res[:filter] = filters_and_queries.size > 1 ? { and: filters_and_queries } : filters_and_queries.first end end res end # @api private # # Simply dups the object for api compatability. # # @return [SearchFlip::Aggregation] The dupped object def fresh dup end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
search_flip-2.0.0.beta3 | lib/search_flip/aggregation.rb |
search_flip-2.0.0.beta2 | lib/search_flip/aggregation.rb |
search_flip-2.0.0.beta | lib/search_flip/aggregation.rb |