Sha256: 1fba469da87c65dde69a02a9ad8de70a9a7f5b286127032dea39b925ace6e24c

Contents?: true

Size: 892 Bytes

Versions: 62

Compression:

Stored size: 892 Bytes

Contents

module Workarea
  module Search
    # TODO remove in v4, unused now
    class FacetMatches
      def initialize(params, facets)
        @params = params
        @facets = facets
      end

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

      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

      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
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.36 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.14 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.35 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.13 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.34 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.12 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.33 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.11 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.10 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.32 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.9 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.31 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.8 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.30 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.7 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.29 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.6 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.28 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.5 app/queries/workarea/search/facet_matches.rb