Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case-insensitive does not work with JSON field type #228

Open
pakomp opened this issue Jun 13, 2023 · 1 comment
Open

Case-insensitive does not work with JSON field type #228

pakomp opened this issue Jun 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@pakomp
Copy link

pakomp commented Jun 13, 2023

Hi,

An Exception will be thrown if setting search.case_sensitive = false, and having a JSON field as searchable. The field is JSON type due to it being translatable (using the package spatie/laravel-translatable).

Exception:
SQLSTATE[42883]: Undefined function: 7 ERROR: function lower(json) does not exist

I'm using Postgresql

EDIT: The problem exists on other field types as well, Orion tries to do lower() on integer columns as well

@pakomp pakomp changed the title Case-insensitive does not work with json Case-insensitive does not work with JSON field type Jun 13, 2023
@alexzarbn alexzarbn added the bug Something isn't working label Aug 21, 2023
@OzanKurt
Copy link

OzanKurt commented Oct 24, 2023

I made it work somehow:

vendor/tailflow/laravel-orion/src/Drivers/Standard/QueryBuilder.php@applySearchingToQueryL429

                    if (!$caseSensitive) {
                        if (str_contains($qualifiedFieldName, '->')) {
                            $grammar = $whereQuery->getGrammar();
                            $qualifiedFieldName = $grammar->wrap($qualifiedFieldName);

                        $whereQuery->orWhereRaw(
                            "lower({$qualifiedFieldName}) like lower(?)",
                            ['%'.$requestedSearchString.'%']
                        );
                        } else {
                        $whereQuery->orWhereRaw(
                            "lower({$qualifiedFieldName}) like lower(?)",
                            ['%'.$requestedSearchString.'%']
                        );
                        }
                    } else {
                        $whereQuery->orWhere(
                            $qualifiedFieldName,
                            'like',
                            '%'.$requestedSearchString.'%'
                        );
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants