From 78bef7683438321bbb0d788f584d7df373327210 Mon Sep 17 00:00:00 2001 From: Aaron Bushnell Date: Tue, 29 Jun 2021 16:15:16 -0400 Subject: [PATCH] Fix boolean values --- CHANGELOG.md | 5 +++++ composer.json | 2 +- src/variables/AlgoliaVariable.php | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c319f..3115124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 062eedc..18ee87e 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/variables/AlgoliaVariable.php b/src/variables/AlgoliaVariable.php index 2e4f1d8..61719f0 100644 --- a/src/variables/AlgoliaVariable.php +++ b/src/variables/AlgoliaVariable.php @@ -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:\"") . "\")";