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.27 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.26 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.45 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.25 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.23 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.44 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.22 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.43 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.21 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.42 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.20 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.41 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.19 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.40 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.18 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.39 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.17 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.38 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.16 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.37 app/queries/workarea/search/facet_matches.rb