X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/5e477e3b5b99da6fc4e54749d4671a6fc8fdcd66..7c869701f02369873c5573236398ec885c4a951f:/lib-sql/functions/ranking.sql?ds=sidebyside diff --git a/lib-sql/functions/ranking.sql b/lib-sql/functions/ranking.sql index af23335a..0b18954c 100644 --- a/lib-sql/functions/ranking.sql +++ b/lib-sql/functions/ranking.sql @@ -284,3 +284,26 @@ BEGIN END; $$ LANGUAGE plpgsql IMMUTABLE; + + +CREATE OR REPLACE FUNCTION weigh_search(search_vector INT[], + term_vectors TEXT[], + weight_vectors FLOAT[], + def_weight FLOAT) + RETURNS FLOAT + AS $$ +DECLARE + pos INT := 1; + terms TEXT; +BEGIN + FOREACH terms IN ARRAY term_vectors + LOOP + IF search_vector @> terms::INTEGER[] THEN + RETURN weight_vectors[pos]; + END IF; + pos := pos + 1; + END LOOP; + RETURN def_weight; +END; +$$ +LANGUAGE plpgsql IMMUTABLE;