Skip to content

Making autocomplete case-insensitive on Postgres #18384

@shinyvision

Description

@shinyvision

Description

Postgres is case sensitive in queries by default, whereas MySQL is not. So if you're using Postgres as your database for Sylius and you search something in an autocomplete field (products or taxons for example) then it only finds results matching the exact casing you've used in your search.

This could be fixed by adding lower() functions in Sylius\Bundle\AdminBundle\Form\Type\TranslatableAutocompleteType.

Maybe you would want this as a configuration option; I'm not sure what the performance impact would be on large databases with MySQL for example.

Example

In src/Sylius/Bundle/AdminBundle/Form/Type/TranslatableAutocompleteType.php:

<?php
...
final class TranslatableAutocompleteType extends AbstractType
{
...
    private static function getComparisons(Expr $expr, array $fields): iterable
    {
        foreach ($fields as $field) {
            yield $expr->like($expr->lower($field), 'LOWER(:query)');
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions