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.4.27 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.4 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.26 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.3 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.25 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.2 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.24 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.1 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.23 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.22 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.0 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.21 app/queries/workarea/search/facet_matches.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.20 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.19 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.18 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.17 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.16 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.15 app/queries/workarea/search/facet_matches.rb
workarea-core-3.4.14 app/queries/workarea/search/facet_matches.rb