kham_pg
kham_pg · Thai word-segmentation FTS parser — tsvector, soundex, RTGS romanization, NER
Overview
PostgreSQL · 14, 15, 16, 17, 18
Usage
Sources:
kham_pg provides Thai full-text search for PostgreSQL. Its kham parser segments text without relying on spaces, while its dictionaries add normalized words, phonetic codes, RTGS romanization, number normalization, part-of-speech lexemes, and named-entity handling to standard tsvector and tsquery workflows.
Core Workflow
kham_tsvector(document) is a convenience wrapper around to_tsvector('kham', document), and kham_tsquery(query) wraps plainto_tsquery('kham', query). Standard highlighting also works:
Text Search Objects
- Parser and ready-to-use configuration:
kham. - Default dictionary:
kham_fts_dict, usinglk82Thai Soundex. - Alternative dictionaries:
kham_fts_dict_udom83andkham_fts_dict_metasound. - Simple lowercasing pass-through dictionary:
kham_dict. - Token types include
thai,latin,number,punct,emoji,unknown, andnamed.
Thai and named-entity tokens can expand to several colocated lexemes, allowing phonetic or Latin-script queries to match Thai text. Thai stopwords are suppressed, Thai digits are normalized alongside ASCII forms, and punctuation and emoji are discarded by the default configuration.
Caveats
Version 0.8.2 is non-relocatable and targets PostgreSQL 14 through 18 in the reviewed upstream release. Segmentation, phonetic expansion, stopword removal, and named-entity recognition affect recall and index size, so validate them with domain-specific Thai text. A GIN expression index matches queries only when they use the same expression and configuration. No preload or restart is required after the library is installed.