Update SearchApiV2Service, fix postgres hashtag search and prepend wildcard operator to improve results

This commit is contained in:
Daniel Supernault 2023-05-02 23:33:06 -06:00
parent 867cbc757c
commit 6e20d0a670
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -125,8 +125,10 @@ 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 . '%';
return Hashtag::where('name', 'like', $query)
$query = Str::startsWith($q, '#') ? '%' . substr($q, 1) . '%' : '%' . $q . '%';
$operator = config('database.default') === 'pgsql' ? 'ilike' : 'like';
return Hashtag::where('name', $operator, $query)
->orWhere('slug', $operator, $query)
->where(function($q) {
return $q->where('can_search', true)
->orWhereNull('can_search');