Class: Workarea::Search::Facet
- Inherits:
-
Filter
- Object
- Filter
- Workarea::Search::Facet
show all
- Defined in:
- app/queries/workarea/search/facet.rb
Instance Attribute Summary
Attributes inherited from Filter
#name, #options, #search
Instance Method Summary
collapse
Methods inherited from Filter
#current_value, #display_name, #initialize, #system_name, #valid_params
Instance Method Details
#aggregation ⇒ Object
54
55
56
|
# File 'app/queries/workarea/search/facet.rb', line 54
def aggregation
raise NotImplementedError
end
|
#aggregation_filter ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/queries/workarea/search/facet.rb', line 9
def aggregation_filter
{
bool: {
must: search
.facets
.reject { |f| f.system_name == system_name }
.map(&:post_filter_clause)
.reject(&:blank?)
}
}
end
|
#params_for(value) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/queries/workarea/search/facet.rb', line 31
def params_for(value)
value = value_to_param(value)
result = valid_params
if selected?(value) && result[system_name].present?
result[system_name].delete(value)
else
result[system_name] = Array(result[system_name])
result[system_name] << value
end
result.delete_if { |_, v| v.blank? }
end
|
#post_filter_clause ⇒ Object
58
59
60
|
# File 'app/queries/workarea/search/facet.rb', line 58
def post_filter_clause
raise NotImplementedError
end
|
#query_clause ⇒ Object
45
46
47
48
|
# File 'app/queries/workarea/search/facet.rb', line 45
def query_clause
end
|
#results ⇒ Object
62
63
64
|
# File 'app/queries/workarea/search/facet.rb', line 62
def results
raise NotImplementedError
end
|
#selected?(value = nil) ⇒ Boolean
26
27
28
29
|
# File 'app/queries/workarea/search/facet.rb', line 26
def selected?(value = nil)
return false if selections.blank?
value.blank? || selections.include?(value_to_param(value))
end
|
#selections ⇒ Object
5
6
7
|
# File 'app/queries/workarea/search/facet.rb', line 5
def selections
Array(params[system_name]).reject(&:blank?)
end
|
#type ⇒ Object
50
51
52
|
# File 'app/queries/workarea/search/facet.rb', line 50
def type
raise NotImplementedError
end
|
#useless? ⇒ Boolean
21
22
23
24
|
# File 'app/queries/workarea/search/facet.rb', line 21
def useless?
selections.blank? &&
(results.empty? || (results.one? && results.first.last == total))
end
|
#value_to_param(value) ⇒ Object
66
67
68
|
# File 'app/queries/workarea/search/facet.rb', line 66
def value_to_param(value)
raise NotImplementedError
end
|