Skip to content

fix(database): make member search accent-insensitive on PostgreSQL - #284

Open
tomudding wants to merge 1 commit into
GEWIS:mainfrom
tomudding:fix/member-search-diacritics
Open

tomudding wants to merge 1 commit into
GEWIS:mainfrom
tomudding:fix/member-search-diacritics

Conversation

@tomudding

Copy link
Copy Markdown
Member

Description

PostgreSQL's LIKE operator is accent-sensitive unlike MariaDB's default collation. Use the unaccent() function (via the unaccent extension) to normalise both the search term and the name columns before comparison, so searching for 'jose garcia' matches 'José García'.

Related issues/external references

Fixes GH-279.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation improvement (no changes to code)
  • Other (please specify)

PostgreSQL's LIKE operator is accent-sensitive unlike MariaDB's default
collation. Use the unaccent() function (via the unaccent extension) to normalise
both the search term and the name columns before comparison, so searching for
'jose garcia' matches 'José García'.

Fixes GEWISGH-279.
@rinkp
rinkp requested a balanced review from Copilot October 9, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new query regresses number, email, graduate, and non-Latin name searches, while its test does not verify accent handling.

5 open findings
What changed in this PR

Makes the PostgreSQL ledger’s member search accent-insensitive for GH-279.

Changes:

  • Adds unaccent-based member searching and PostgreSQL extension migration.
  • Adds integration coverage and updates the PHPStan baseline.
File Description
src/​Repository/​Database/​MemberRepository.php Reimplements member lookup using native PostgreSQL SQL.
migrations/​database/​Version20261009191800.php Enables the unaccent extension.
tests/​Integration/​Repository/​Database/​MemberSearchTest.php Adds member-search integration tests.
phpstan-baseline.neon Removes an obsolete suppression.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +92 to +95
$searchTerm = transliterator_transliterate(
'Any-Latin; Latin-ASCII',
$query,
);
Comment on lines +107 to +111
(
CONCAT(LOWER(unaccent(m.firstName)), ' ', LOWER(unaccent(m.lastName))) LIKE :name
OR CONCAT(LOWER(unaccent(m.firstName)), ' ', LOWER(unaccent(m.middleName)), ' ',
LOWER(unaccent(m.lastName))) LIKE :name
)
Comment on lines +114 to +120
AND EXISTS (
SELECT 1
FROM Membership ms
WHERE ms.member_lidnr = m.lidnr
AND ms.type IN ('ordinary', 'external', 'honorary')
AND (ms.endDate IS NULL OR ms.endDate >= NOW())
)
Comment on lines +73 to +83
public function testSearchHandlesDiacritics(): void
{
// The unaccent extension is enabled in setUp; verify it works by
// searching for a common name fragment. This test primarily ensures
// the query using unaccent() executes without error.
$results = $this->repository->search('a');
self::assertNotEmpty(
$results,
'Search with unaccent should return results',
);
}
Comment on lines +90 to +91
// Uses a native query so we can call PostgreSQL's to_ascii() to strip diacritics; MariaDB does this by
// default (accent-insensitive collation), but PostgreSQL requires an explicit function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Member search does not like diacritics

2 participants