From 6e20d0a6709c67b6b43475f4c22676ec6c5c6db5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:33:06 -0600 Subject: [PATCH] Update SearchApiV2Service, fix postgres hashtag search and prepend wildcard operator to improve results --- app/Services/SearchApiV2Service.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index a6826b77e..93a29cae9 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -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');