From 0a98b7ad20fff56fed8409961da692e66f75f410 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 8 Apr 2025 02:11:26 -0600 Subject: [PATCH] Update SearchApiV2Service, fix offset bug. Fixes #5875 --- app/Services/SearchApiV2Service.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index f17fe3e84..6d28c949f 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -132,7 +132,6 @@ class SearchApiV2Service $q = $this->query->input('q'); $limit = $this->query->input('limit') ?? 20; $offset = $this->query->input('offset') ?? 0; - $query = Str::startsWith($q, '#') ? substr($q, 1) : $q; $query = $query.'%'; @@ -214,6 +213,9 @@ class SearchApiV2Service $user = request()->user(); $mastodonMode = self::$mastodonMode; $query = urldecode($this->query->input('q')); + $limit = $this->query->input('limit') ?? 20; + $offset = $this->query->input('offset') ?? 0; + $banned = InstanceService::getBannedDomains(); $domainBlocks = UserFilterService::domainBlocks($user->profile_id); if ($domainBlocks && count($domainBlocks)) { @@ -252,7 +254,12 @@ class SearchApiV2Service if (in_array($domain, $banned)) { return $default; } - $default['accounts'][] = $res; + $paginated = collect($res)->take($limit)->skip($offset)->toArray(); + if (! empty($paginated)) { + $default['accounts'][] = $paginated; + } else { + $default['accounts'] = []; + } return $default; } else { @@ -271,7 +278,12 @@ class SearchApiV2Service if (in_array($domain, $banned)) { return $default; } - $default['accounts'][] = $res; + $paginated = collect($res)->take($limit)->skip($offset)->toArray(); + if (! empty($paginated)) { + $default['accounts'][] = $paginated; + } else { + $default['accounts'] = []; + } return $default; } else {