From 1992b5bc90425af566e0be451343e23689e2f5a4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 4 Mar 2023 14:36:17 -0700 Subject: [PATCH] Update SearchApiV2Service, fix hashtag search. --- app/Services/SearchApiV2Service.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index f5703c7e5..64c8303e7 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -122,11 +122,15 @@ class SearchApiV2Service protected function hashtags() { $mastodonMode = self::$mastodonMode; + $q = $this->query->input('q'); $limit = $this->query->input('limit') ?? 20; $offset = $this->query->input('offset') ?? 0; - $query = $this->query->input('q') . '%'; - return Hashtag::where('can_search', true) - ->where('name', 'like', $query) + $query = Str::startsWith($q, '#') ? substr($q, 1) . '%' : $q . '%'; + return Hashtag::where('name', 'like', $query) + ->where(function($q) { + return $q->where('can_search', true) + ->orWhereNull('can_search'); + }) ->offset($offset) ->limit($limit) ->get()