From c23bbde99712a804cb6cc3deb8801e6d69f431be Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Mon, 6 Jan 2025 16:06:31 +0100 Subject: [PATCH 1/4] fix forced lower case search --- packages/support/src/helpers.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 43b9c6430b7..be8ec25f30e 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -181,6 +181,12 @@ function generate_search_column_expression(string $column, ?bool $isSearchForced }; if ($isSearchForcedCaseInsensitive) { + if (in_array($driverName, ['mysql', 'mariadb'], true) && str_contains($column, '->')) { + [$field, $path] = invade($databaseConnection->getQueryGrammar())->wrapJsonFieldAndPath($column); + + $column = "json_extract({$field}{$path})"; + } + $column = "lower({$column})"; } From d47632c0583bac481d4ce7cc9b6b1711d0f8e0fc Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Mon, 6 Jan 2025 16:14:39 +0100 Subject: [PATCH 2/4] add ignore for phpstan --- packages/support/src/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index be8ec25f30e..3601d95206b 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -182,7 +182,7 @@ function generate_search_column_expression(string $column, ?bool $isSearchForced if ($isSearchForcedCaseInsensitive) { if (in_array($driverName, ['mysql', 'mariadb'], true) && str_contains($column, '->')) { - [$field, $path] = invade($databaseConnection->getQueryGrammar())->wrapJsonFieldAndPath($column); + [$field, $path] = invade($databaseConnection->getQueryGrammar())->wrapJsonFieldAndPath($column); /** @phpstan-ignore-line */ $column = "json_extract({$field}{$path})"; } From 353a46d8b7168c14f0662a6b417f29e42856e9ec Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Tue, 7 Jan 2025 10:07:02 +0100 Subject: [PATCH 3/4] use str helper --- packages/support/src/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 3601d95206b..68a9c6f7005 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -181,7 +181,7 @@ function generate_search_column_expression(string $column, ?bool $isSearchForced }; if ($isSearchForcedCaseInsensitive) { - if (in_array($driverName, ['mysql', 'mariadb'], true) && str_contains($column, '->')) { + if (in_array($driverName, ['mysql', 'mariadb'], true) && str($column)->contains('->')) { [$field, $path] = invade($databaseConnection->getQueryGrammar())->wrapJsonFieldAndPath($column); /** @phpstan-ignore-line */ $column = "json_extract({$field}{$path})"; From 215e66238f11556da53676f57765c18752bb1767 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Tue, 7 Jan 2025 10:07:29 +0100 Subject: [PATCH 4/4] exclude the case when json extract is already the start of the column name --- packages/support/src/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 68a9c6f7005..f13319ba522 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -181,7 +181,7 @@ function generate_search_column_expression(string $column, ?bool $isSearchForced }; if ($isSearchForcedCaseInsensitive) { - if (in_array($driverName, ['mysql', 'mariadb'], true) && str($column)->contains('->')) { + if (in_array($driverName, ['mysql', 'mariadb'], true) && str($column)->contains('->') && ! str($column)->startsWith('json_extract(')) { [$field, $path] = invade($databaseConnection->getQueryGrammar())->wrapJsonFieldAndPath($column); /** @phpstan-ignore-line */ $column = "json_extract({$field}{$path})";