From 8d67c1f820aaec8d52ce8c1eb04a15ff0c4d81d9 Mon Sep 17 00:00:00 2001 From: Zack Pollard Date: Thu, 9 Apr 2026 01:56:07 +0100 Subject: [PATCH] fix(server): people search not showing for 3 or less characters (#27629) Co-authored-by: Mert <101130780+mertalev@users.noreply.github.com> --- server/src/queries/person.repository.sql | 8 +++++++- server/src/repositories/person.repository.ts | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/src/queries/person.repository.sql b/server/src/queries/person.repository.sql index f60b8859f2..318c151cca 100644 --- a/server/src/queries/person.repository.sql +++ b/server/src/queries/person.repository.sql @@ -195,13 +195,19 @@ where "asset_face"."id" = $2 -- PersonRepository.getByName +with + "similarity_threshold" as ( + select + set_config('pg_trgm.word_similarity_threshold', '0.5', true) as "thresh" + ) select "person".* from + "similarity_threshold", "person" where "person"."ownerId" = $1 - and f_unaccent ("person"."name") %>> f_unaccent ($2) + and f_unaccent ("person"."name") %> f_unaccent ($2) order by f_unaccent ("person"."name") <->>> f_unaccent ($3) limit diff --git a/server/src/repositories/person.repository.ts b/server/src/repositories/person.repository.ts index c1c21162a2..ab5fad40d1 100644 --- a/server/src/repositories/person.repository.ts +++ b/server/src/repositories/person.repository.ts @@ -310,10 +310,13 @@ export class PersonRepository { @GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING, { withHidden: true }] }) getByName(userId: string, personName: string, { withHidden }: PersonNameSearchOptions) { return this.db - .selectFrom('person') + .with('similarity_threshold', (db) => + db.selectNoFrom(sql`set_config('pg_trgm.word_similarity_threshold', '0.5', true)`.as('thresh')), + ) + .selectFrom(['similarity_threshold', 'person']) .selectAll('person') .where('person.ownerId', '=', userId) - .where(() => sql`f_unaccent("person"."name") %>> f_unaccent(${personName})`) + .where(() => sql`f_unaccent("person"."name") %> f_unaccent(${personName})`) .orderBy(sql`f_unaccent("person"."name") <->>> f_unaccent(${personName})`) .limit(100) .$if(!withHidden, (qb) => qb.where('person.isHidden', '=', false))