Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Search/Comb/Comb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Search/CombTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down