66
77use CodelyTv \Shared \Domain \Criteria \Filter ;
88use CodelyTv \Shared \Domain \Criteria \FilterOperator ;
9- use function Lambdish \ Phunctional \ get ;
9+ use Exception ;
1010
1111final class ElasticQueryGenerator
1212{
@@ -15,14 +15,7 @@ final class ElasticQueryGenerator
1515 private const TERM_TERM = 'term ' ;
1616 private const TERM_RANGE = 'range ' ;
1717 private const TERM_WILDCARD = 'wildcard ' ;
18- private static array $ termMapping = [
19- FilterOperator::EQUAL => self ::TERM_TERM ,
20- FilterOperator::NOT_EQUAL => '!= ' ,
21- FilterOperator::GT => self ::TERM_RANGE ,
22- FilterOperator::LT => self ::TERM_RANGE ,
23- FilterOperator::CONTAINS => self ::TERM_WILDCARD ,
24- FilterOperator::NOT_CONTAINS => self ::TERM_WILDCARD ,
25- ];
18+
2619 private static array $ mustNotFields = [FilterOperator::NOT_EQUAL , FilterOperator::NOT_CONTAINS ];
2720
2821 public function __invoke (array $ query , Filter $ filter ): array
@@ -53,6 +46,12 @@ private function typeFor(FilterOperator $operator): string
5346
5447 private function termLevelFor (FilterOperator $ operator ): string
5548 {
56- return get ($ operator ->value (), self ::$ termMapping );
49+ return match ($ operator ->value ()) {
50+ FilterOperator::EQUAL => self ::TERM_TERM ,
51+ FilterOperator::NOT_EQUAL => '!= ' ,
52+ FilterOperator::GT , FilterOperator::LT => self ::TERM_RANGE ,
53+ FilterOperator::CONTAINS , FilterOperator::NOT_CONTAINS => self ::TERM_WILDCARD ,
54+ default => throw new Exception ("Unexpected match value {$ operator ->value ()}" ),
55+ };
5756 }
5857}
0 commit comments