Class: Workarea::Search::FacetMatches

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

Overview

TODO remove in v4, unused now

Instance Method Summary collapse

Constructor Details

#initialize(params, facets) ⇒ FacetMatches

Returns a new instance of FacetMatches.



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

def initialize(params, facets)
  @params = params
  @facets = facets
end

Instance Method Details

#matchesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/queries/workarea/search/facet_matches.rb', line 14

def matches
  @matches ||= @facets.reduce({}) do |memo, facet|
    facet.results.keys.each do |value|
      if query =~ /(^|\s+)#{Regexp.quote(value.to_s)}(\s+|$)/i
        memo[facet.system_name] ||= []
        memo[facet.system_name] << value
      end
    end

    memo
  end
end

#paramsObject



27
28
29
30
31
32
33
34
35
36
# File 'app/queries/workarea/search/facet_matches.rb', line 27

def params
  return @params unless matches.keys.one?

  @_params ||= matches.reduce(@params) do |memo, tuple|
    name, values = *tuple
    memo[name] ||= []
    memo[name].push(*values)
    memo
  end
end

#queryObject



10
11
12
# File 'app/queries/workarea/search/facet_matches.rb', line 10

def query
  @query ||= @params[:q].try(:strip).to_s
end