Class: Workarea::Search::HelpSearch
- Inherits:
-
Object
- Object
- Workarea::Search::HelpSearch
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_sorts ⇒ Object
Instance Method Details
#current_sort ⇒ Object
23
24
25
|
# File 'app/queries/workarea/search/help_search.rb', line 23
def current_sort
self.class.available_sorts.find(params[:sort])
end
|
#facets ⇒ Object
45
46
47
|
# File 'app/queries/workarea/search/help_search.rb', line 45
def facets
@facets ||= [TermsFacet.new(self, 'category')]
end
|
#post_filter ⇒ Object
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
|
#query ⇒ Object
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_query ⇒ Object
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
|
#sort ⇒ Object
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
|