From 21687f9ab163382787d1ff8187a48d5711a4736d Mon Sep 17 00:00:00 2001 From: Mira Date: Mon, 23 Jun 2025 22:06:22 +0200 Subject: [PATCH] ek filter in header --- app/Elastic/SongLyricSearchableTrait.php | 5 ++++- app/GraphQL/Queries/SearchSongLyrics.php | 8 ++++---- app/Scopes/EKSongsScope.php | 24 ++++++++++++++++++++++++ app/SongLyric.php | 3 +++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 app/Scopes/EKSongsScope.php diff --git a/app/Elastic/SongLyricSearchableTrait.php b/app/Elastic/SongLyricSearchableTrait.php index ea8139a1..2d862e7c 100644 --- a/app/Elastic/SongLyricSearchableTrait.php +++ b/app/Elastic/SongLyricSearchableTrait.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Builder; use App\Scopes\EvangelicalSongsScope; +use App\Scopes\EKSongsScope; use App\Scopes\ExcludeEvangelicalOnlySongsScope; @@ -271,7 +272,9 @@ function ($q) { }, ]); - $q = $q->withoutGlobalScope(ExcludeEvangelicalOnlySongsScope::class)->withoutGlobalScope(EvangelicalSongsScope::class); + $q = $q->withoutGlobalScope(ExcludeEvangelicalOnlySongsScope::class) + ->withoutGlobalScope(EvangelicalSongsScope::class) + ->withoutGlobalScope(EKSongsScope::class); return $q; } diff --git a/app/GraphQL/Queries/SearchSongLyrics.php b/app/GraphQL/Queries/SearchSongLyrics.php index 1d21edc6..a0da0da3 100644 --- a/app/GraphQL/Queries/SearchSongLyrics.php +++ b/app/GraphQL/Queries/SearchSongLyrics.php @@ -44,11 +44,11 @@ public function __invoke($rootValue, array $args, GraphQLContext $context, Resol // We need to manually apply the same filter that is implied by the song lyric (global) scope, // (see ExcludeEvangelicalOnlySongsScope and EvangelicalSongsScope) // because they work only for Eloquent, not Elasticsearch, which confuses Scout. - $filter_ez = Request::header('Filter-Content') == 'ez'; - if ($filter_ez) { - $ez_songbook_id = Songbook::where('shortcut', 'ez')->first()->id; + $filter_shortcut = Request::header('Filter-Content'); + if ($filter_shotcut == 'ez' || $filter_shortcut == 'ek') { + $songbook_id = Songbook::where('shortcut', $filter_shortcut)->first()->id; $searchParams['query']['bool']['filter'][] = [ - 'terms' => ['songbook_records.songbook_id' => [$ez_songbook_id]] + 'terms' => ['songbook_records.songbook_id' => [$songbook_id]] ]; } else { $searchParams['query']['bool']['must_not'] = [ diff --git a/app/Scopes/EKSongsScope.php b/app/Scopes/EKSongsScope.php new file mode 100644 index 00000000..350bcdd8 --- /dev/null +++ b/app/Scopes/EKSongsScope.php @@ -0,0 +1,24 @@ +whereHas('songbook_records', function ($q) { + $q->where('shortcut', "EK"); + }); + } +} \ No newline at end of file diff --git a/app/SongLyric.php b/app/SongLyric.php index e418ed7f..c70885db 100644 --- a/app/SongLyric.php +++ b/app/SongLyric.php @@ -34,6 +34,7 @@ use App\Elastic\SongLyricSearchableTrait; use App\Scopes\EvangelicalSongsScope; +use App\Scopes\EKSongsScope; use Illuminate\Support\Facades\Request; /** @@ -188,6 +189,8 @@ protected static function booted() if (Request::header('Filter-Content') == 'ez') { // limit the songs to only those that are in the Evangelical songbook static::addGlobalScope(new EvangelicalSongsScope); + } else if (Request::header('Filter-Content') == 'ek') { + static::addGlobalScope(new EKSongsScope); } else { static::addGlobalScope(new ExcludeEvangelicalOnlySongsScope); }