pg_textsearch
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_textsearch | 1.0.0 | FTS | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2180 | pg_textsearch | No | Yes | Yes | Yes | No | No | - |
| Related | pg_search pgroonga pg_bigm zhparser pg_trgm rum biscuit fuzzystrmatch |
|---|
bm25 am conflicts with pg_search; must be preloaded via shared_preload_libraries.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.0 | 1817161514 | pg_textsearch | - |
| RPM | PIGSTY | 1.0.0 | 1817161514 | pg_textsearch_$v | - |
| DEB | PIGSTY | 1.0.0 | 1817161514 | postgresql-$v-textsearch | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.0 el8.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el8.aarch64 | PIGSTY 1.0.0 el8.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el9.x86_64 | PIGSTY 1.0.0 el9.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el9.aarch64 | PIGSTY 1.0.0 el9.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el10.x86_64 | PIGSTY 1.0.0 el10.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY 1.0.0 el10.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 1.0.0 d12.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d12.aarch64 | PIGSTY 1.0.0 d12.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d13.x86_64 | PIGSTY 1.0.0 d13.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~trixie_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY 1.0.0 d13.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~trixie_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 1.0.0 u22.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~jammy_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u22.aarch64 | PIGSTY 1.0.0 u22.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~jammy_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u24.x86_64 | PIGSTY 1.0.0 u24.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~noble_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u24.aarch64 | PIGSTY 1.0.0 u24.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_1.0.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_1.0.0-1PIGSTY~noble_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
Build
You can build the RPM / DEB packages for pg_textsearch using pig build:
pig build pkg pg_textsearch # build RPM / DEB packages
Install
You can install pg_textsearch directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_textsearch; # Install for current active PG version
pig ext install -y pg_textsearch -v 18 # PG 18
pig ext install -y pg_textsearch -v 17 # PG 17
dnf install -y pg_textsearch_18 # PG 18
dnf install -y pg_textsearch_17 # PG 17
apt install -y postgresql-18-textsearch # PG 18
apt install -y postgresql-17-textsearch # PG 17
Preload:
shared_preload_libraries = 'pg_textsearch';
Create Extension:
CREATE EXTENSION pg_textsearch;
Usage
Sources: README, release notes, Timescale changelog
pg_textsearch provides BM25-ranked full-text search for PostgreSQL with a bm25 access method and the <@> scoring operator. Upstream marks v1.0.0 as production ready.
Enable the extension
shared_preload_libraries = 'pg_textsearch'
CREATE EXTENSION pg_textsearch;
Build a BM25 index and query it
CREATE TABLE documents (id bigserial PRIMARY KEY, content text);
CREATE INDEX docs_idx
ON documents USING bm25(content)
WITH (text_config = 'english');
SELECT *
FROM documents
ORDER BY content <@> 'database system'
LIMIT 5;
The README notes that <@> returns the negative BM25 score, so lower values are better matches.
Explicit queries and index options
SELECT *
FROM documents
ORDER BY content <@> to_bm25query('database system', 'docs_idx')
LIMIT 5;
CREATE INDEX ON documents USING bm25(content)
WITH (text_config = 'english', k1 = 1.5, b = 0.8);
The README also documents expression indexes, partial indexes, and multilingual partial indexes.
Useful functions and GUCs
SELECT bm25_force_merge('docs_idx');
Documented GUCs in current upstream docs include:
pg_textsearch.default_limitpg_textsearch.segments_per_levelpg_textsearch.memory_limitpg_textsearch.log_scores
Caveats
pg_textsearchcurrently supports PostgreSQL 17 and 18 upstream.- Inside PL/pgSQL and stored procedures, the implicit
text <@> 'query'form does not use planner hooks; upstream says to useto_bm25query()with an explicit index name there. v1.0.0adds the production-ready status,bm25_force_merge(), and newer GUCs documented in the official changelog and README.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.