From ad6672620ae61939243b445c24d0321389a689bb Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 21 Aug 2023 06:34:23 -0700 Subject: [PATCH] Update multisearch for exclusions --- app/controllers/api/v1/search_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb index 37731bd..9ab81f3 100644 --- a/app/controllers/api/v1/search_controller.rb +++ b/app/controllers/api/v1/search_controller.rb @@ -30,20 +30,26 @@ module Api end def search_all_en - PgSearch.multisearch_options = { using: TRIGRAM } - results = PgSearch.multisearch(search_params[:query]).limit(10) + query = search_params[:query] + exclude = search_params[:exclude] - if (results.length < 5) && (search_params[:query].length >= 2) + PgSearch.multisearch_options = { using: TRIGRAM } + results = PgSearch.multisearch(query).where.not(granblue_id: exclude).limit(10) + + if (results.length < 5) && (query.length >= 2) PgSearch.multisearch_options = { using: TSEARCH_WITH_PREFIX } - results = PgSearch.multisearch(search_params[:query]).limit(10) + results = PgSearch.multisearch(query).where.not(granblue_id: exclude).limit(10) end results end def search_all_ja + query = search_params[:query] + exclude = search_params[:exclude] + PgSearch.multisearch_options = { using: TSEARCH_WITH_PREFIX } - PgSearch.multisearch(search_params[:query]).limit(10) + PgSearch.multisearch(query).where.not(granblue_id: exclude).limit(10) end def characters