I have a question regarding pg_search: I installed the gem on solidus 2.9 and added a product_decorator.rb model like this:
Spree::Product.class_eval do
include PgSearch::Model
pg_search_scope :search, against: [:name, :description, :meta_description, :meta_keywords],
using: {tsearch: {dictionary: "english"}}
end
It works fine in rails console.
How can I make it work when I use the search field in solidus' frontend? I tried adding it to the product controller but can't seem to make it work. Thanks!
UPDATE
So after kennyadsl's comments I have this:
#lib/mystore/products_search.rb
module MyStore
class ProductSearch < Spree::Core::Search::Base
def retrieve_products
Spree::Product.pg_search
end
end
end
#models/spree/product_decorator.rb
Spree::Product.class_eval do
include PgSearch::Model
pg_search_scope :search, against: [:name, :description, :meta_description, :meta_keywords], using: {tsearch: {dictionary: "english"}}
def self.text_search(keywords)
if keywords.present?
search(keywords)
else
Spree::Product.all
end
end
end
#controllers/products_controller.rb
def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products(params)
end