Class: Workarea::Search::Facet

Inherits:
Filter
  • Object
show all
Defined in:
app/queries/workarea/search/facet.rb

Direct Known Subclasses

RangeFacet, TermsFacet

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

Constructor Details

This class inherits a constructor from Workarea::Search::Filter

Instance Method Details

#aggregationObject

Raises:

  • (NotImplementedError)


54
55
56
# File 'app/queries/workarea/search/facet.rb', line 54

def aggregation
  raise NotImplementedError
end

#aggregation_filterObject



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_clauseObject

Raises:

  • (NotImplementedError)


58
59
60
# File 'app/queries/workarea/search/facet.rb', line 58

def post_filter_clause
  raise NotImplementedError
end

#query_clauseObject



45
46
47
48
# File 'app/queries/workarea/search/facet.rb', line 45

def query_clause
  # no op, facets will be applied in post_filter to allow aggregation
  # to display all options without being affected by selections.
end

#resultsObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'app/queries/workarea/search/facet.rb', line 62

def results
  raise NotImplementedError
end

#selected?(value = nil) ⇒ Boolean

Returns:

  • (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

#selectionsObject



5
6
7
# File 'app/queries/workarea/search/facet.rb', line 5

def selections
  Array(params[system_name]).reject(&:blank?)
end

#typeObject

Raises:

  • (NotImplementedError)


50
51
52
# File 'app/queries/workarea/search/facet.rb', line 50

def type
  raise NotImplementedError
end

#useless?Boolean

Returns:

  • (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

Raises:

  • (NotImplementedError)


66
67
68
# File 'app/queries/workarea/search/facet.rb', line 66

def value_to_param(value)
  raise NotImplementedError
end