Class: RediSearch::Aggregate::Clauses::GroupBy
Instance Method Summary
collapse
-
#average(property:, as: nil) ⇒ Object
-
#clause ⇒ Object
-
#count(as: nil) ⇒ Object
-
#distinct_count(property:, as: nil) ⇒ Object
-
#distinctish_count(property:, as: nil) ⇒ Object
-
#initialize(fields:) ⇒ GroupBy
constructor
A new instance of GroupBy.
-
#max(property:, as: nil) ⇒ Object
-
#min(property:, as: nil) ⇒ Object
-
#quantile(property:, quantile:, as: nil) ⇒ Object
-
#stdev(property:, as: nil) ⇒ Object
-
#sum(property:, as: nil) ⇒ Object
-
#to_list(property:, as: nil) ⇒ Object
#clause_order, clause_order, clause_term
included, #validate!
Constructor Details
#initialize(fields:) ⇒ GroupBy
Returns a new instance of GroupBy.
10
11
12
13
14
15
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 10
def initialize(fields:)
@fields = fields.map(&:to_s).map do |field|
field.prepend("@") unless field.start_with?("@")
end
@reducer = nil
end
|
Instance Method Details
#average(property:, as: nil) ⇒ Object
52
53
54
55
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 52
def average(property:, as: nil)
self.reducer = Reducers::Average.
new(property: property, as: as).tap(&:validate!)
end
|
#clause ⇒ Object
17
18
19
20
21
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 17
def clause
validate!
["GROUPBY", fields.count, *fields, *reducer&.clause].compact
end
|
#count(as: nil) ⇒ Object
23
24
25
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 23
def count(as: nil)
self.reducer = Reducers::Count.new(as: as).tap(&:validate!)
end
|
#distinct_count(property:, as: nil) ⇒ Object
27
28
29
30
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 27
def distinct_count(property:, as: nil)
self.reducer = Reducers::DistinctCount.
new(property: property, as: as).tap(&:validate!)
end
|
#distinctish_count(property:, as: nil) ⇒ Object
32
33
34
35
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 32
def distinctish_count(property:, as: nil)
self.reducer = Reducers::DistinctishCount.
new(property: property, as: as).tap(&:validate!)
end
|
#max(property:, as: nil) ⇒ Object
47
48
49
50
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 47
def max(property:, as: nil)
self.reducer = Reducers::Max.
new(property: property, as: as).tap(&:validate!)
end
|
#min(property:, as: nil) ⇒ Object
42
43
44
45
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 42
def min(property:, as: nil)
self.reducer = Reducers::Min.
new(property: property, as: as).tap(&:validate!)
end
|
#quantile(property:, quantile:, as: nil) ⇒ Object
62
63
64
65
66
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 62
def quantile(property:, quantile:, as: nil)
self.reducer = Reducers::Quantile.new(
property: property, quantile: quantile, as: as
).tap(&:validate!)
end
|
#stdev(property:, as: nil) ⇒ Object
57
58
59
60
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 57
def stdev(property:, as: nil)
self.reducer = Reducers::Stdev.
new(property: property, as: as).tap(&:validate!)
end
|
#sum(property:, as: nil) ⇒ Object
37
38
39
40
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 37
def sum(property:, as: nil)
self.reducer = Reducers::Sum.
new(property: property, as: as).tap(&:validate!)
end
|
#to_list(property:, as: nil) ⇒ Object
68
69
70
71
|
# File 'lib/redi_search/aggregate/clauses/group_by.rb', line 68
def to_list(property:, as: nil)
self.reducer = Reducers::ToList.
new(property: property, as: as).tap(&:validate!)
end
|