X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/5e477e3b5b99da6fc4e54749d4671a6fc8fdcd66..0af8dac3d35a94afe0b6ad775f3226d8d147501d:/lib-sql/functions/ranking.sql?ds=sidebyside

diff --git a/lib-sql/functions/ranking.sql b/lib-sql/functions/ranking.sql
index af23335a..97a0cde3 100644
--- a/lib-sql/functions/ranking.sql
+++ b/lib-sql/functions/ranking.sql
@@ -284,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;
