Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Last active December 15, 2015 08:38
Show Gist options
  • Save rturowicz/5232002 to your computer and use it in GitHub Desktop.
Save rturowicz/5232002 to your computer and use it in GitHub Desktop.
postgresql: tsearch2 indexed substrings
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