1
0
Fork 0
forked from mirror/pixelfed

Update SearchApiV2Service, improve account search results

This commit is contained in:
Daniel Supernault 2023-02-07 23:08:23 -07:00
parent 6deb09de28
commit f6a588f9cf
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -88,16 +88,17 @@ class SearchApiV2Service
$offset = $this->query->input('offset') ?? 0; $offset = $this->query->input('offset') ?? 0;
$rawQuery = $initalQuery ? $initalQuery : $this->query->input('q'); $rawQuery = $initalQuery ? $initalQuery : $this->query->input('q');
$query = $rawQuery . '%'; $query = $rawQuery . '%';
if(Str::substrCount($rawQuery, '@') >= 1 && Str::contains($rawQuery, config('pixelfed.domain.app'))) { $webfingerQuery = $query;
$deliminatorCount = Str::substrCount($rawQuery, '@'); if(Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) !== '@') {
$query = explode('@', $rawQuery)[$deliminatorCount == 1 ? 0 : 1]; $query = '@' . $query;
} }
if(Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) == '@') { if(substr($webfingerQuery, 0, 1) !== '@') {
$query = substr($rawQuery, 1) . '%'; $webfingerQuery = '@' . $webfingerQuery;
} }
$banned = InstanceService::getBannedDomains(); $banned = InstanceService::getBannedDomains();
$results = Profile::select('username', 'id', 'followers_count', 'domain') $results = Profile::select('username', 'id', 'followers_count', 'domain')
->where('username', 'like', $query) ->where('username', 'like', $query)
->orWhere('webfinger', 'like', $webfingerQuery)
->orderByDesc('profiles.followers_count') ->orderByDesc('profiles.followers_count')
->offset($offset) ->offset($offset)
->limit($limit) ->limit($limit)