From 34231ef1afd48d87c1ab5c093c3ac5fe04c52ba5 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Sun, 9 Jul 2023 10:52:01 +0100 Subject: [PATCH] changed default behavior when searching - instead of ordering by mal_id or popularity, weighted relevancy search happens based on the model's config --- app/Features/AnimeSearchHandler.php | 10 ---------- app/Features/MangaSearchHandler.php | 10 ---------- app/Features/SearchRequestHandler.php | 8 +------- 3 files changed, 1 insertion(+), 27 deletions(-) diff --git a/app/Features/AnimeSearchHandler.php b/app/Features/AnimeSearchHandler.php index 333294c..43293c9 100644 --- a/app/Features/AnimeSearchHandler.php +++ b/app/Features/AnimeSearchHandler.php @@ -25,14 +25,4 @@ class AnimeSearchHandler extends SearchRequestHandler { return new AnimeCollection($paginator); } - - protected function prepareOrderByParam(Collection $requestData): Collection - { - if ($requestData->has("q") && !$requestData->has("order_by")) { - // default order by should be popularity, as MAL seems to use this trick. - $requestData->offsetSet("order_by", AnimeOrderByEnum::popularity()); - } - - return parent::prepareOrderByParam($requestData); - } } diff --git a/app/Features/MangaSearchHandler.php b/app/Features/MangaSearchHandler.php index 1fe8af0..a3c883a 100644 --- a/app/Features/MangaSearchHandler.php +++ b/app/Features/MangaSearchHandler.php @@ -28,14 +28,4 @@ class MangaSearchHandler extends SearchRequestHandler { return new MangaCollection($paginator); } - - protected function prepareOrderByParam(Collection $requestData): Collection - { - if ($requestData->has("q") && !$requestData->has("order_by")) { - // default order by should be popularity, as MAL seems to use this trick. - $requestData->offsetSet("order_by", MangaOrderByEnum::popularity()); - } - - return parent::prepareOrderByParam($requestData); - } } diff --git a/app/Features/SearchRequestHandler.php b/app/Features/SearchRequestHandler.php index 3ccee07..e4851cf 100644 --- a/app/Features/SearchRequestHandler.php +++ b/app/Features/SearchRequestHandler.php @@ -48,17 +48,11 @@ abstract class SearchRequestHandler implements RequestHandler protected function prepareOrderByParam(Collection $requestData): Collection { - if (!$requestData->has('order_by') || !$requestData->get('order_by') instanceof Enum) { - $requestData->offsetSet('order_by', 'mal_id'); - return $requestData; - } - - if ($requestData->has('order_by')) { + if ($requestData->has('order_by') && !is_null($requestData->get("order_by"))) { $requestData->offsetSet("order_by", $requestData->get("order_by")->label); return $requestData; } - $requestData->offsetSet("order_by", 'mal_id'); return $requestData; } }