Move from pg_trgm to full-text search for autofill

This commit is contained in:
Maciej Ziarkowski 2020-01-09 15:35:38 +00:00
parent 11743dc983
commit 494ec52afb

View File

@ -6,9 +6,12 @@ const autofillFunctionMap = {
function getLanduseClassOptions(value: string) { function getLanduseClassOptions(value: string) {
return db.manyOrNone(` 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 FROM reference_tables.buildings_landuse_class
WHERE description % $1 WHERE to_tsvector(description) @@ plainto_tsquery($1)
ORDER BY similarity DESC, description ORDER BY similarity DESC, description
`, [value] `, [value]
); );