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