소스 검색

Update SearchApiV2Service, fix hashtag search.

Daniel Supernault 2 년 전
부모
커밋
1992b5bc90
1개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  1. 7 3
      app/Services/SearchApiV2Service.php

+ 7 - 3
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()