Class: Workarea::Search::ProductSearch
Constant Summary
collapse
- PASSES =
[0, 1, 2]
Class Method Summary
collapse
Instance Method Summary
collapse
#load_inventory_from, #load_model_from, #load_pricing_from
Methods included from Pagination
#each_by, #from, #page, #per_page, #results, #size
#query_suggestion_response, #query_suggestions, #sanitized_query, #should_use_suggestion?, #suggest
#product_rule_filters, #product_rules_query_clauses
#active_for_segments_clause, #displayable_when_out_of_stock_sort_clause, #inventory_display_clause, #preview_current_release_clause, #product_display_query_clauses
Methods included from Facets
#facets, #range_facets, #terms_facets
Methods included from Query
#additional_options, #body, #id, #initialize, #load_model_from, #loaded_results, #query_string, #response, #results, #scroll, #stats, #total
Class Method Details
.available_sorts ⇒ Object
Instance Method Details
#aggregations ⇒ Object
41
42
43
|
# File 'app/queries/workarea/search/product_search.rb', line 41
def aggregations
facets.map(&:aggregation).reduce(&:merge)
end
|
#boosted_fields ⇒ Object
71
72
73
74
75
76
|
# File 'app/queries/workarea/search/product_search.rb', line 71
def boosted_fields
text_fields = pass > PASSES.first ? boosts : boosts.except(:description)
text_fields.map do |name, boost|
"content.#{name}^#{boost || 1}"
end
end
|
#boosts ⇒ Object
64
65
66
67
68
69
|
# File 'app/queries/workarea/search/product_search.rb', line 64
def boosts
result = Search::Settings.current.boosts.presence ||
Workarea.config.default_search_boosts
result.with_indifferent_access
end
|
#customization ⇒ Object
57
58
59
60
61
62
|
# File 'app/queries/workarea/search/product_search.rb', line 57
def customization
return @customization if defined?(@customization)
result = Customization.find_by_query(params[:q])
@customization = result.active? ? result : Customization.new
end
|
#default_operator ⇒ Object
78
79
80
|
# File 'app/queries/workarea/search/product_search.rb', line 78
def default_operator
pass > PASSES.second ? 'OR' : 'AND'
end
|
#pass ⇒ Object
53
54
55
|
# File 'app/queries/workarea/search/product_search.rb', line 53
def pass
params[:pass] || PASSES.first
end
|
#post_filter ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/queries/workarea/search/product_search.rb', line 45
def post_filter
{
bool: {
must: facets.map(&:post_filter_clause).reject(&:blank?)
}
}
end
|
#query ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/queries/workarea/search/product_search.rb', line 27
def query
result = {
bool: {
must: product_display_query_clauses + product_rules_query_clauses
}
}
if params[:q].present? && !query_string.all?
result[:bool][:must] << query_string_clause
end
result
end
|
#selected_sort ⇒ Object
120
121
122
|
# File 'app/queries/workarea/search/product_search.rb', line 120
def selected_sort
self.class.available_sorts.find(params[:sort])
end
|
#sort ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'app/queries/workarea/search/product_search.rb', line 82
def sort
result = []
if selected_sort.field.present?
result << {
selected_sort.field => {
order: selected_sort.direction,
missing: '_last',
unmapped_type: 'float'
}
}
else
result << {
"sorts.#{query_string.id}" => {
order: 'asc',
missing: '_last',
unmapped_type: 'float'
}
}
end
result << displayable_when_out_of_stock_sort_clause
result << { _score: :desc }
result << {
'sorts.orders_score': {
order: 'desc',
missing: '_last',
unmapped_type: 'float'
}
}
result
end
|
#sorts ⇒ Object
116
117
118
|
# File 'app/queries/workarea/search/product_search.rb', line 116
def sorts
Array(params[:sort])
end
|