Last active
December 15, 2015 08:38
-
-
Save rturowicz/5232002 to your computer and use it in GitHub Desktop.
postgresql: tsearch2 indexed substrings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alter table towar add ftssubnpelna tsvector; | |
CREATE INDEX towar_ftssubnpelna_idx ON towar USING gin(ftssubnpelna); | |
CREATE or replace FUNCTION text_to_substrings(tekst text) RETURNS text AS $$ | |
substrings = [] | |
for tmp in tekst.split(): | |
for i in range(len(tmp)): | |
if i >= 3: | |
substrings.append(tmp[0:i]) | |
return ' '.join(substrings) | |
$$ LANGUAGE plpythonu SECURITY DEFINER; | |
update towar set ftssubnpelna = to_tsvector(text_to_substrings(nazwapelna)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment