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 @@ -726,7 +726,11 @@ private function removeDisallowedMatches($params)

// string pruned results together
foreach ($item['pruned'] as $pruned) {
$record .= ' '.$pruned;
if (is_array($pruned)) {
$record .= ' '.$this->flattenArray($pruned);
} else {
$record .= ' '.$pruned;
}
}

// check for disallowed
Expand Down
28 changes: 28 additions & 0 deletions tests/Search/CombTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,34 @@ public function it_can_search_for_umlauts()
$this->assertSame(2, $result['info']['total_results']);
}

#[Test]
public function it_filters_out_results_with_disallowed_words()
{
$comb = new Comb([
['title' => 'Pizza', 'ingredients' => 'Tomato, Cheese, Bread'],
['title' => 'Tomato Soup', 'ingredients' => 'Tomato, Water, Salt'],
['title' => 'Chicken & Sweetcorn Soup', 'ingredients' => 'Chicken, Sweetcorn, Water'],
]);

$results = $comb->lookUp('soup -tomato');

$this->assertEquals(['Chicken & Sweetcorn Soup'], collect($results['data'] ?? [])->pluck('data.title')->all());
}

#[Test]
public function it_filters_out_results_with_disallowed_words_where_results_are_arrays()
{
$comb = new Comb([
['title' => 'Pizza', 'ingredients' => ['Tomato', 'Cheese', 'Bread']],
['title' => 'Tomato Soup', 'ingredients' => ['Tomato', 'Water', 'Salt']],
['title' => 'Chicken & Sweetcorn Soup', 'ingredients' => ['Chicken', 'Sweetcorn', 'Water']],
]);

$results = $comb->lookUp('soup -tomato');

$this->assertEquals(['Chicken & Sweetcorn Soup'], collect($results['data'] ?? [])->pluck('data.title')->all());
}

public static function searchesProvider()
{
return [
Expand Down
Loading