From 0c43766a5198a1db1d199447d8a29dc346673bfd Mon Sep 17 00:00:00 2001 From: Sascha Karnatz Date: Tue, 8 Oct 2024 14:35:20 +0200 Subject: [PATCH] Introduce a search_class configuration into Alchemy The default config is Alchemy::PgSearch, but it is possible to change the class from outside. --- app/controller/alchemy/pg_search/controller_methods.rb | 2 +- lib/alchemy-pg_search.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controller/alchemy/pg_search/controller_methods.rb b/app/controller/alchemy/pg_search/controller_methods.rb index fc59ec0..e9a2540 100644 --- a/app/controller/alchemy/pg_search/controller_methods.rb +++ b/app/controller/alchemy/pg_search/controller_methods.rb @@ -47,7 +47,7 @@ def perform_search # @return [Array] # def search_results - Alchemy::PgSearch.search params[:query], ability: current_ability + Alchemy.search_class.search params[:query], ability: current_ability end # A view helper that loads the search result page. diff --git a/lib/alchemy-pg_search.rb b/lib/alchemy-pg_search.rb index c7424bc..2e79354 100644 --- a/lib/alchemy-pg_search.rb +++ b/lib/alchemy-pg_search.rb @@ -2,6 +2,9 @@ require "alchemy/pg_search/config" module Alchemy + mattr_accessor :search_class + @@search_class = PgSearch + module PgSearch SEARCHABLE_INGREDIENTS = %w[Text Richtext Picture]