fix(server): people search not showing for 3 or less characters (#27629)

Co-authored-by: Mert <101130780+mertalev@users.noreply.github.com>
This commit is contained in:
Zack Pollard
2026-04-09 01:56:07 +01:00
committed by GitHub
parent ed0ec30917
commit 8d67c1f820
2 changed files with 12 additions and 3 deletions
+7 -1
View File
@@ -195,13 +195,19 @@ where
"asset_face"."id" = $2 "asset_face"."id" = $2
-- PersonRepository.getByName -- PersonRepository.getByName
with
"similarity_threshold" as (
select
set_config('pg_trgm.word_similarity_threshold', '0.5', true) as "thresh"
)
select select
"person".* "person".*
from from
"similarity_threshold",
"person" "person"
where where
"person"."ownerId" = $1 "person"."ownerId" = $1
and f_unaccent ("person"."name") %>> f_unaccent ($2) and f_unaccent ("person"."name") %> f_unaccent ($2)
order by order by
f_unaccent ("person"."name") <->>> f_unaccent ($3) f_unaccent ("person"."name") <->>> f_unaccent ($3)
limit limit
+5 -2
View File
@@ -310,10 +310,13 @@ export class PersonRepository {
@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING, { withHidden: true }] }) @GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING, { withHidden: true }] })
getByName(userId: string, personName: string, { withHidden }: PersonNameSearchOptions) { getByName(userId: string, personName: string, { withHidden }: PersonNameSearchOptions) {
return this.db 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') .selectAll('person')
.where('person.ownerId', '=', userId) .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})`) .orderBy(sql`f_unaccent("person"."name") <->>> f_unaccent(${personName})`)
.limit(100) .limit(100)
.$if(!withHidden, (qb) => qb.where('person.isHidden', '=', false)) .$if(!withHidden, (qb) => qb.where('person.isHidden', '=', false))