Browse Source

updated lu_text_match

tags/v0.1.1
Robin Thoni 7 years ago
parent
commit
b09e55ff5f
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      postgresql/docker-entrypoint-initdb.d/01_luticate2_utils.sql

+ 9
- 1
postgresql/docker-entrypoint-initdb.d/01_luticate2_utils.sql View File

@@ -84,13 +84,21 @@ INSERT INTO lu_entities_history ("table", "data") VALUES(TG_TABLE_NAME, to_json(
84 84
 return NEW;
85 85
 END$$;
86 86
 
87
+--
88
+-- Name: lu_text_match_prepare(text); Type: FUNCTION; Schema: public; Owner: dev
89
+--
90
+
91
+CREATE FUNCTION lu_text_match_prepare(data text) RETURNS text
92
+    LANGUAGE sql
93
+        AS $$SELECT regexp_replace(unaccent(data), '[^a-zA-Z0-9]+', ' ', 'g')$$;
94
+
87 95
 --
88 96
 -- Name: lu_text_match(text, text); Type: FUNCTION; Schema: public; 
89 97
 --
90 98
 
91 99
 CREATE FUNCTION lu_text_match(query text, data text) RETURNS boolean
92 100
     LANGUAGE sql
93
-    AS $$SELECT unaccent(data) ILIKE  ('%' || unaccent(query) || '%') AS result$$;
101
+    AS $$SELECT lu_text_match_prepare(data) ILIKE  ('%' || lu_text_match_prepare(query) || '%') AS result$$;
94 102
 
95 103
 --
96 104
 -- Name: lu_texts_match(text, text[]); Type: FUNCTION; Schema: public; 

Loading…
Cancel
Save