songRepository = $songRepository; $this->albumRepository = $albumRepository; $this->artistRepository = $artistRepository; } /** @return array */ public function excerptSearch(string $keywords, int $count): array { return [ 'songs' => self::getTopResults($this->songRepository->search($keywords), $count) ->map(static function (Song $song): string { return $song->id; }), 'artists' => self::getTopResults($this->artistRepository->search($keywords), $count) ->map(static function (Artist $artist): int { return $artist->id; }), 'albums' => self::getTopResults($this->albumRepository->search($keywords), $count) ->map(static function (Album $album): int { return $album->id; }), ]; } /** @return Collection|array */ private static function getTopResults(Builder $query, int $count): Collection { return $query->take($count)->get(); } /** @return Collection|array */ public function searchSongs(string $keywords): Collection { return $this->songRepository ->search($keywords) ->get() ->map(static function (Song $song): string { return $song->id; }); } }