Sha256: 9d1efb04caf11cb626192de4556591071c1d838a37582863a4a23685bef1055f

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Workarea
  module Storefront
    class ContentSearchViewModel < ApplicationViewModel
      include Pagination
      include SearchCustomizationContent
      include ContentSearchResults

      ContentResult = Struct.new(:name, :resource_name, :summary, :to_param)

      def search_query
        content_query
      end

      def content
        @content ||=
          begin
            results = content_query.results.map do |result|
              ContentResult.new(
                result['content']['name'],
                result['cache']['resource_name'],
                result['content']['summary'],
                result['slug']
              )
            end

            PagedArray.from(results, page, per_page, total)
          end
      end

      def query_suggestions
        @query_suggestions ||=
          begin
            all = Recommendation::Searches.find(options[:q]) +
                  model.query_suggestions

            all.take(3)
          end
      end

      def sort
        content_query.class.available_sorts.find(options[:sort])
      end

      def sorts
        content_query.class.available_sorts.map { |s| [s.name, s.slug] }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-content_search-1.1.0 app/view_models/workarea/storefront/content_search_view_model.rb
workarea-content_search-1.0.9 app/view_models/workarea/storefront/content_search_view_model.rb
workarea-content_search-1.0.8 app/view_models/workarea/storefront/content_search_view_model.rb