X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b9517c99ae6297c2ab908d7fa324efd2d1b2f43a..dc7cfd1708da6fceb268d2efaaf92ef513a20234:/lib-sql/functions/ranking.sql diff --git a/lib-sql/functions/ranking.sql b/lib-sql/functions/ranking.sql index 1f236211..97a0cde3 100644 --- a/lib-sql/functions/ranking.sql +++ b/lib-sql/functions/ranking.sql @@ -1,3 +1,10 @@ +-- SPDX-License-Identifier: GPL-2.0-only +-- +-- This file is part of Nominatim. (https://nominatim.org) +-- +-- Copyright (C) 2022 by the Nominatim developer community. +-- For a full list of authors see the git log. + -- Functions related to search and address ranks -- Return an approximate search radius according to the search rank. @@ -277,3 +284,24 @@ BEGIN END; $$ LANGUAGE plpgsql IMMUTABLE; + + +CREATE OR REPLACE FUNCTION weigh_search(search_vector INT[], + rankings TEXT, + def_weight FLOAT) + RETURNS FLOAT + AS $$ +DECLARE + rank JSON; +BEGIN + FOR rank IN + SELECT * FROM json_array_elements(rankings::JSON) + LOOP + IF true = ALL(SELECT x::int = ANY(search_vector) FROM json_array_elements_text(rank->1) as x) THEN + RETURN (rank->>0)::float; + END IF; + END LOOP; + RETURN def_weight; +END; +$$ +LANGUAGE plpgsql IMMUTABLE;