From f6a588f9cfd90912af1645b13e061afff1fce8e9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 7 Feb 2023 23:08:23 -0700 Subject: [PATCH] Update SearchApiV2Service, improve account search results --- app/Services/SearchApiV2Service.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index 0471224b8..f5703c7e5 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -88,16 +88,17 @@ class SearchApiV2Service $offset = $this->query->input('offset') ?? 0; $rawQuery = $initalQuery ? $initalQuery : $this->query->input('q'); $query = $rawQuery . '%'; - if(Str::substrCount($rawQuery, '@') >= 1 && Str::contains($rawQuery, config('pixelfed.domain.app'))) { - $deliminatorCount = Str::substrCount($rawQuery, '@'); - $query = explode('@', $rawQuery)[$deliminatorCount == 1 ? 0 : 1]; + $webfingerQuery = $query; + if(Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) !== '@') { + $query = '@' . $query; } - if(Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) == '@') { - $query = substr($rawQuery, 1) . '%'; + if(substr($webfingerQuery, 0, 1) !== '@') { + $webfingerQuery = '@' . $webfingerQuery; } $banned = InstanceService::getBannedDomains(); $results = Profile::select('username', 'id', 'followers_count', 'domain') ->where('username', 'like', $query) + ->orWhere('webfinger', 'like', $webfingerQuery) ->orderByDesc('profiles.followers_count') ->offset($offset) ->limit($limit)