Skip to content

Instantly share code, notes, and snippets.

@tudoanh
Forked from anhtran/commands.sql
Created April 4, 2024 00:32
Show Gist options
  • Save tudoanh/7ff7456358aa0557024619eafc4a8f6c to your computer and use it in GitHub Desktop.
Save tudoanh/7ff7456358aa0557024619eafc4a8f6c to your computer and use it in GitHub Desktop.
Cách tạo cấu hình cho tiếng Việt trong PostgreSQL (stopwords, ispell)
CREATE TEXT SEARCH DICTIONARY public.vietnamese (
TEMPLATE = pg_catalog.simple,
STOPWORDS = vietnamese
);
CREATE TEXT SEARCH CONFIGURATION public.vietnamese (
COPY = pg_catalog.english
);
ALTER TEXT SEARCH CONFIGURATION public.vietnamese
ALTER MAPPING
FOR asciiword, asciihword, hword_asciipart, hword, hword_part, word
WITH vietnamese;
SELECT to_tsvector('vietnamese', 'Nhiều địa phương cấm người ra đường khi bão Noru đổ bộ');
Tham khảo:
https://www.postgresql.org/docs/current/textsearch-dictionaries.html
Tải file stop words của tiếng Việt:
https://github.com/stopwords/vietnamese-stopwords/blob/master/vietnamese-stopwords.txt
Sau khi tải về, hãy đổi tên thành `vietnamese.stop` sau đó move đến thư mục:
`/place-where-installed-postgresql/share/postgresql/tsearch_data`
Lưu ý: cấu hình trên chỉ có tác dụng với DB hiện hành. Nghĩa là bạn dùng DB nào thì hãy select DB đó và thực thi các lệnh trên chứ postgres không có apply global.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment