diff --git a/src/Search/Comb/Comb.php b/src/Search/Comb/Comb.php index caab9e1c03a..d51c652f3b7 100644 --- a/src/Search/Comb/Comb.php +++ b/src/Search/Comb/Comb.php @@ -1009,8 +1009,12 @@ private function filterStopWords($words) return $words; } + $lowercasedStopWords = collect($this->stop_words) + ->map(fn ($word) => Str::lower($word)) + ->all(); + foreach ($words as $key => $word) { - if (in_array($word, $this->stop_words)) { + if (in_array(Str::lower($word), $lowercasedStopWords)) { unset($words[$key]); } } diff --git a/tests/Search/CombTest.php b/tests/Search/CombTest.php index 897dea3fe21..44584920740 100644 --- a/tests/Search/CombTest.php +++ b/tests/Search/CombTest.php @@ -281,6 +281,22 @@ public function it_filters_out_results_with_disallowed_words_where_results_are_a $this->assertEquals(['Chicken & Sweetcorn Soup'], collect($results['data'] ?? [])->pluck('data.title')->all()); } + #[Test] + public function it_handles_stop_words_case_insensitive() + { + $comb = new Comb([ + ['title' => 'One two three'], + ['title' => 'Three four five'], + ['title' => 'Five four three'], + ]); + + $comb->setSettings(['stop_words' => ['Three']]); + + $results = $comb->lookUp('One two three'); + + $this->assertEquals(['One two three'], collect($results['data'] ?? [])->pluck('data.title')->all()); + } + public static function searchesProvider() { return [