Skip to content

Commit

Permalink
Fix boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbushnell committed Jun 29, 2021
1 parent 9fb0d47 commit 78bef76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Algolia

## 3.0.1 - 2021-06-29

### Fixed
* Coerce filters with boolean values to a string value of `"true"` or `"false"` to cooperate with Algolia syntax engine

## 3.0.0 - 2021-06-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "trendyminds/algolia",
"description": "Easily pull search results from Algolia into your Craft CMS website",
"type": "craft-plugin",
"version": "3.0.0",
"version": "3.0.1",
"keywords": [
"craft",
"cms",
Expand Down
9 changes: 9 additions & 0 deletions src/variables/AlgoliaVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public function parseFilters(array $filters = []): string
->filter(function ($item) {
// Remove filters that are either "null" or empty
return gettype($item) !== 'NULL' && $item !== '';
})->map(function ($items) {
// If we have a boolean value we need to coerce it to a string of 'true' or 'false'. Otherwise Algolia will not understand the syntax
return collect($items)->map(function ($item) {
if (gettype($item) === 'boolean') {
return $item === true ? 'true' : 'false';
}

return $item;
});
})->map(function ($item, $group) {
// Convert each group of results into string-based "OR" searches for Algolia's parsing engine
return "($group:\"" . collect($item)->join("\" OR $group:\"") . "\")";
Expand Down

0 comments on commit 78bef76

Please sign in to comment.