Class: Orchestrate::Search::AggregateBuilder

Inherits:
Object
  • Object
show all
Includes:
QueryBuilderDelegator
Defined in:
lib/orchestrate/search/aggregate_builder.rb

Overview

Aggregate Builder object for constructing aggregate params included in a search

Instance Attribute Summary collapse

Aggregate Functions collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ AggregateBuilder

Initialize a new AggregateBuilder object

Parameters:

  • builder (Orchestrate::Search::SearchBuilder)

    The Search Builder object



24
25
26
27
# File 'lib/orchestrate/search/aggregate_builder.rb', line 24

def initialize(builder)
  @builder = builder
  @aggregates = []
end

Instance Attribute Details

#aggregatesArray (readonly)

Returns Aggregate param arguments.

Returns:

  • (Array)

    Aggregate param arguments



20
21
22
# File 'lib/orchestrate/search/aggregate_builder.rb', line 20

def aggregates
  @aggregates
end

#builderQueryBuilder (readonly)

Returns:



17
18
19
# File 'lib/orchestrate/search/aggregate_builder.rb', line 17

def builder
  @builder
end

Instance Method Details

#distance(field_name) ⇒ DistanceBuilder

Parameters:

  • field_name (#to_s)

Returns:



70
71
72
73
74
# File 'lib/orchestrate/search/aggregate_builder.rb', line 70

def distance(field_name)
  dist = DistanceBuilder.new(self, "#{field_name}")
  aggregates << dist
  dist
end

#range(field_name) ⇒ RangeBuilder

Parameters:

  • field_name (#to_s)

Returns:



62
63
64
65
66
# File 'lib/orchestrate/search/aggregate_builder.rb', line 62

def range(field_name)
  rng = RangeBuilder.new(self, "#{field_name}")
  aggregates << rng
  rng
end

#stats(field_name) ⇒ AggregateBuilder

Parameters:

  • field_name (#to_s)

Returns:



54
55
56
57
58
# File 'lib/orchestrate/search/aggregate_builder.rb', line 54

def stats(field_name)
  stat = StatsBuilder.new(self, "#{field_name}")
  aggregates << stat
  stat
end

#time_series(field_name) ⇒ TimeSeriesBuilder

Parameters:

  • field_name (#to_s)

Returns:



78
79
80
81
82
# File 'lib/orchestrate/search/aggregate_builder.rb', line 78

def time_series(field_name)
  time = TimeSeriesBuilder.new(self, "#{field_name}")
  aggregates << time
  time
end

#to_paramObject

Returns constructed aggregate string parameter for search query.

Returns:

  • constructed aggregate string parameter for search query



36
37
38
# File 'lib/orchestrate/search/aggregate_builder.rb', line 36

def to_param
  aggregates.map {|agg| agg.to_param }.join(',')
end

#to_sObject Also known as: inspect

Returns Pretty-Printed string representation of the AggregateBuilder object.

Returns:

  • Pretty-Printed string representation of the AggregateBuilder object



30
31
32
# File 'lib/orchestrate/search/aggregate_builder.rb', line 30

def to_s
  "#<Orchestrate::Search::AggregateBuilder collection=#{collection.name} query=#{builder.query} aggregate=#{to_param}>"
end

#top_values(field_name, offset = nil, limit = nil) ⇒ AggregateBuilder

Parameters:

  • field_name (#to_s)
  • offset (Integer, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: nil)

Returns:



46
47
48
49
50
# File 'lib/orchestrate/search/aggregate_builder.rb', line 46

def top_values(field_name, offset = nil, limit = nil)
  top_values = TopValuesBuilder.new(self, "#{field_name}", offset, limit)
  aggregates << top_values
  top_values
end