Class: Workarea::Search::HelpSearch

Inherits:
Object
  • Object
show all
Includes:
Facets, Pagination, Query
Defined in:
app/queries/workarea/search/help_search.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pagination

#each_by, #from, #page, #per_page, #results, #size

Methods included from Facets

#range_facets, #terms_facets

Methods included from Query

#additional_options, #aggregations, #body, #id, #initialize, #load_model_from, #loaded_results, #query_string, #response, #results, #scroll, #stats, #total

Class Method Details

.available_sortsObject



10
11
12
13
14
15
16
17
# File 'app/queries/workarea/search/help_search.rb', line 10

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

Instance Method Details

#current_sortObject



23
24
25
# File 'app/queries/workarea/search/help_search.rb', line 23

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

#facetsObject



45
46
47
# File 'app/queries/workarea/search/help_search.rb', line 45

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

#post_filterObject



37
38
39
40
41
42
43
# File 'app/queries/workarea/search/help_search.rb', line 37

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

#queryObject



27
28
29
30
31
32
33
34
35
# File 'app/queries/workarea/search/help_search.rb', line 27

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

#sanitized_queryObject



19
20
21
# File 'app/queries/workarea/search/help_search.rb', line 19

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

#sortObject



49
50
51
52
53
54
55
# File 'app/queries/workarea/search/help_search.rb', line 49

def sort
  if current_sort.field.present?
    [{ current_sort.field => current_sort.direction }]
  else
    [{ _score: :desc }, { created_at: :desc }]
  end
end