From 494ec52afb1303b3c5907648abc809a15b32a63c Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 9 Jan 2020 15:35:38 +0000 Subject: [PATCH] Move from pg_trgm to full-text search for autofill --- app/src/api/services/autofill.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/api/services/autofill.ts b/app/src/api/services/autofill.ts index 41e78174..8ecd6709 100644 --- a/app/src/api/services/autofill.ts +++ b/app/src/api/services/autofill.ts @@ -6,9 +6,12 @@ const autofillFunctionMap = { function getLanduseClassOptions(value: string) { return db.manyOrNone(` - SELECT landuse_id AS id, description as value, similarity(description, $1) AS similarity + SELECT + landuse_id AS id, + description as value, + ts_rank(to_tsvector(description), plainto_tsquery($1)) as similarity FROM reference_tables.buildings_landuse_class - WHERE description % $1 + WHERE to_tsvector(description) @@ plainto_tsquery($1) ORDER BY similarity DESC, description `, [value] );