Sha256: f45d7d9bd7bb94a2f91d78da31c69e2f9dcbacd301cf7b9f398f39577d4f4e42

Contents?: true

Size: 1.17 KB

Versions: 62

Compression:

Stored size: 1.17 KB

Contents

module Workarea
  module Search
    class HelpSearch
      include Query
      include Facets
      include Pagination

      document Search::Help

      def self.available_sorts
        Sort::Collection.new(
          Sort.relevance,
          Sort.newest,
          Sort.name_asc,
          Sort.name_desc
        )
      end

      def sanitized_query
        @sanitized_query ||= QueryString.new(params[:q]).sanitized.presence || '*'
      end

      def current_sort
        self.class.available_sorts.find(params[:sort])
      end

      def query
        {
          query_string: {
            query: sanitized_query,
            fields: %w(name^1.5 facets^0.75 body),
            use_dis_max: true
          }
        }
      end

      def post_filter
        {
          bool: {
            must: facets.map(&:post_filter_clause).reject(&:blank?)
          }
        }
      end

      def facets
        @facets ||= [TermsFacet.new(self, 'category')]
      end

      def sort
        if current_sort.field.present?
          [{ current_sort.field => current_sort.direction }]
        else
          [{ _score: :desc }, { created_at: :desc }]
        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/help_search.rb
workarea-core-3.5.26 app/queries/workarea/search/help_search.rb
workarea-core-3.4.45 app/queries/workarea/search/help_search.rb
workarea-core-3.5.25 app/queries/workarea/search/help_search.rb
workarea-core-3.5.23 app/queries/workarea/search/help_search.rb
workarea-core-3.4.44 app/queries/workarea/search/help_search.rb
workarea-core-3.5.22 app/queries/workarea/search/help_search.rb
workarea-core-3.4.43 app/queries/workarea/search/help_search.rb
workarea-core-3.5.21 app/queries/workarea/search/help_search.rb
workarea-core-3.4.42 app/queries/workarea/search/help_search.rb
workarea-core-3.5.20 app/queries/workarea/search/help_search.rb
workarea-core-3.4.41 app/queries/workarea/search/help_search.rb
workarea-core-3.5.19 app/queries/workarea/search/help_search.rb
workarea-core-3.4.40 app/queries/workarea/search/help_search.rb
workarea-core-3.5.18 app/queries/workarea/search/help_search.rb
workarea-core-3.4.39 app/queries/workarea/search/help_search.rb
workarea-core-3.5.17 app/queries/workarea/search/help_search.rb
workarea-core-3.4.38 app/queries/workarea/search/help_search.rb
workarea-core-3.5.16 app/queries/workarea/search/help_search.rb
workarea-core-3.4.37 app/queries/workarea/search/help_search.rb