]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib-sql/tokenizer/icu_tokenizer.sql
introduce and use analyzer for postcodes
[nominatim.git] / lib-sql / tokenizer / icu_tokenizer.sql
index a3dac8ddcbe82eb5fd6057bd81bb9b823befa159..f323334b88c5e4c65c38c998d1bbaac839bcec61 100644 (file)
@@ -223,3 +223,26 @@ BEGIN
 END;
 $$
 LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION create_postcode_word(postcode TEXT, lookup_terms TEXT[])
+  RETURNS BOOLEAN
+  AS $$
+DECLARE
+  existing INTEGER;
+BEGIN
+  SELECT count(*) INTO existing
+    FROM word WHERE word = postcode and type = 'P';
+
+  IF existing > 0 THEN
+    RETURN TRUE;
+  END IF;
+
+  -- postcodes don't need word ids
+  INSERT INTO word (word_token, type, word)
+    SELECT lookup_term, 'P', postcode FROM unnest(lookup_terms) as lookup_term;
+
+  RETURN FALSE;
+END;
+$$
+LANGUAGE plpgsql;
+