]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib-sql/functions/ranking.sql
fix merge issues
[nominatim.git] / lib-sql / functions / ranking.sql
index af23335a862cbbb511f133937c149aa6fecd4e85..97a0cde38e2b6aa6ef8aebf63af2611894502fbd 100644 (file)
@@ -284,3 +284,24 @@ BEGIN
 END;
 $$
 LANGUAGE plpgsql IMMUTABLE;
 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;