Class: RediSearch::Aggregate
- Inherits:
-
Object
- Object
- RediSearch::Aggregate
show all
- Extended by:
- Forwardable
- Includes:
- LazilyLoad, Search::Queries
- Defined in:
- lib/redi_search/aggregate.rb,
lib/redi_search/aggregate/clauses/load.rb,
lib/redi_search/aggregate/reducers/max.rb,
lib/redi_search/aggregate/reducers/min.rb,
lib/redi_search/aggregate/reducers/sum.rb,
lib/redi_search/aggregate/clauses/apply.rb,
lib/redi_search/aggregate/clauses/limit.rb,
lib/redi_search/aggregate/clauses/filter.rb,
lib/redi_search/aggregate/reducers/count.rb,
lib/redi_search/aggregate/reducers/stdev.rb,
lib/redi_search/aggregate/clauses/sort_by.rb,
lib/redi_search/aggregate/clauses/group_by.rb,
lib/redi_search/aggregate/clauses/verbatim.rb,
lib/redi_search/aggregate/reducers/average.rb,
lib/redi_search/aggregate/reducers/to_list.rb,
lib/redi_search/aggregate/reducers/quantile.rb,
lib/redi_search/aggregate/reducers/distinct_count.rb,
lib/redi_search/aggregate/reducers/distinctish_count.rb
Defined Under Namespace
Modules: Clauses, Reducers
Classes: MissingGroupByClause
Instance Attribute Summary collapse
Instance Method Summary
collapse
#and, #not, #or, #where
Methods included from LazilyLoad
#inspect, #loaded?, #pretty_print, #to_a
Constructor Details
#initialize(index, term = nil, **term_options) ⇒ Aggregate
Returns a new instance of Aggregate.
16
17
18
19
20
21
22
|
# File 'lib/redi_search/aggregate.rb', line 16
def initialize(index, term = nil, **term_options)
@index = index
@clauses = []
@used_clauses = Set.new
@query = term && Search::Queries::And.new(self, term, nil, **term_options)
end
|
Instance Attribute Details
#clauses ⇒ Object
Returns the value of attribute clauses.
12
13
14
|
# File 'lib/redi_search/aggregate.rb', line 12
def clauses
@clauses
end
|
#index ⇒ Object
Returns the value of attribute index.
12
13
14
|
# File 'lib/redi_search/aggregate.rb', line 12
def index
@index
end
|
#query ⇒ Object
Returns the value of attribute query.
12
13
14
|
# File 'lib/redi_search/aggregate.rb', line 12
def query
@query
end
|
#used_clauses ⇒ Object
Returns the value of attribute used_clauses.
12
13
14
|
# File 'lib/redi_search/aggregate.rb', line 12
def used_clauses
@used_clauses
end
|
Instance Method Details
#apply(expression, as:) ⇒ Object
68
69
70
|
# File 'lib/redi_search/aggregate.rb', line 68
def apply(expression, as:)
add_to_clauses(Clauses::Apply.new(expression: expression, as: as))
end
|
#count(as: nil) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/redi_search/aggregate.rb', line 36
def count(as: nil)
clause = clauses.reverse.find { |cl| cl.is_a?(Clauses::GroupBy) } ||
raise(MissingGroupByClause, "call group_by first")
clause.count(as: as)
self
end
|
#filter(expression) ⇒ Object
72
73
74
|
# File 'lib/redi_search/aggregate.rb', line 72
def filter(expression)
add_to_clauses(Clauses::Filter.new(expression: expression))
end
|
#group_by(*fields) ⇒ Object
32
33
34
|
# File 'lib/redi_search/aggregate.rb', line 32
def group_by(*fields)
add_to_clauses(Clauses::GroupBy.new(fields: fields))
end
|
#limit(total, offset = 0) ⇒ Object
76
77
78
|
# File 'lib/redi_search/aggregate.rb', line 76
def limit(total, offset = 0)
add_to_clauses(Clauses::Limit.new(total: total, offset: offset))
end
|
#load(*fields) ⇒ Object
28
29
30
|
# File 'lib/redi_search/aggregate.rb', line 28
def load(*fields)
add_to_clauses(Clauses::Load.new(fields: fields))
end
|
#quantile(property: nil, quantile: nil, as: nil) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/redi_search/aggregate.rb', line 44
def quantile(property: nil, quantile: nil, as: nil)
clause = clauses.reverse.find { |cl| cl.is_a?(Clauses::GroupBy) } ||
raise(MissingGroupByClause, "call group_by first")
clause.count(property: property, quantile: quantile, as: as)
self
end
|
#sort_by(*fields) ⇒ Object
64
65
66
|
# File 'lib/redi_search/aggregate.rb', line 64
def sort_by(*fields)
add_to_clauses(Clauses::SortBy.new(fields: fields))
end
|
#verbatim ⇒ Object
24
25
26
|
# File 'lib/redi_search/aggregate.rb', line 24
def verbatim
add_to_clauses(Clauses::Verbatim.new)
end
|