I need to override the get_products_conditions_for
method in this class, what's the best way of doing this?
I've tried adding this to an initializer:
Spree::Search::Base.class_eval do
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
which results in this error when starting the server: uninitialized constant Spree::Search (NameError)
I've also tried adding this to "/lib/spree/search/base.rb" and "/lib/spree/search/tags_search.rb"
module Spree::Search
class TagsSearch < Spree::Search::Base
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
end
and then Spree::Config.searcher = TagsSearch
in application.rb...
I've even tried completely replacing the file by placing a replica in the same directory structure within the app, either nothing happens, or I get the mentioned errors...
What I'm trying to do is integrate acts_as_taggable_on
which is done and working, however the search obviously does not return results from these tags...
EDIT: Ok so after Steph's answer I've tried:
module Spree::Search
class TagsSearch < Spree::Search::Base
def get_products_conditions_for(base_scope, query)
base_scope.like_any([:name, :description], query.split) | base_scope.joins("JOIN taggings on taggings.taggable_id = spree_products.id JOIN tags on tags.id = taggings.tag_id").where("tags.name = ?", query.split)
end
end
end
in app/models/search/tags_search.rb
and Steph's code suggestion in lib/spree/search/tags_search.rb
and this:
config.to_prepare do
Spree::Core::Search::Base.send(:include, TagsSearch)
end
in config/environments/development.rb
which results in the following when starting the server:
uninitialized constant TagsSearch (NameError)