Class: Workarea::Search::RangeFacet
- Inherits:
-
Facet
show all
- Defined in:
- app/queries/workarea/search/range_facet.rb
Instance Attribute Summary
Attributes inherited from Filter
#name, #options, #search
Instance Method Summary
collapse
Methods inherited from Facet
#aggregation_filter, #params_for, #query_clause, #selected?, #selections, #useless?
Methods inherited from Filter
#current_value, #display_name, #initialize, #params_for, #query_clause, #selected?, #system_name, #useless?, #valid_params
Instance Method Details
#aggregation ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/queries/workarea/search/range_facet.rb', line 20
def aggregation
{
system_name => {
filter: aggregation_filter,
aggs: {
system_name => {
range: { field: "numeric.#{system_name}", ranges: options }
}
}
}
}
end
|
#post_filter_clause ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/queries/workarea/search/range_facet.rb', line 8
def post_filter_clause
return unless selections.present?
{
bool: {
should: selections
.map { |s| RangeParameter.new(s).to_filter }
.map { |f| { range: { "numeric.#{system_name}" => f } } }
}
}
end
|
#results ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/queries/workarea/search/range_facet.rb', line 33
def results
results = search.response.dig(
'aggregations',
system_name,
system_name,
'buckets'
)
results ||= []
results.reduce({}) do |memo, result|
if result['doc_count'] > 0
key = {}
key[:from] = result['from'] if result['from'].present?
key[:to] = result['to'] if result['to'].present?
memo[key] = result['doc_count']
end
memo
end
end
|
#type ⇒ Object
4
5
6
|
# File 'app/queries/workarea/search/range_facet.rb', line 4
def type
:range
end
|
#value_to_param(value) ⇒ Object
55
56
57
|
# File 'app/queries/workarea/search/range_facet.rb', line 55
def value_to_param(value)
RangeParameter.to_param(value)
end
|