Class: Spree::Core::Search::Variant
- Inherits:
-
Object
- Object
- Spree::Core::Search::Variant
- Defined in:
- lib/spree/core/search/variant.rb
Overview
NOTE: Use Spree::Config.variant_search_class rather than referencing this directly.
Instance Method Summary collapse
-
#initialize(query_string, scope: Spree::Variant.all) ⇒ Variant
constructor
A new instance of Variant.
-
#results ⇒ Object
Searches the variants table using the ransack ‘search_terms’ defined on the class.
Constructor Details
Instance Method Details
#results ⇒ Object
Searches the variants table using the ransack ‘search_terms’ defined on the class. Each word of the query string is searched individually, matching by a union of the ransack search terms, then we find the intersection of those queries, ensuring that each word matches one of the rules.
Returns:
ActiveRecord::Relation of variants
35 36 37 38 39 40 41 42 43 |
# File 'lib/spree/core/search/variant.rb', line 35 def results return @scope if @query_string.blank? matches = @query_string.split.map do |word| @scope.ransack(search_term_params(word)).result.pluck(:id) end @scope.where(id: matches.inject(:&)) end |