pg_textsearch
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_textsearch | 0.5.0 | FTS | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2180 | pg_textsearch | No | Yes | No | Yes | No | Yes | - |
| Related | pg_search pgroonga pg_bigm zhparser pg_trgm rum biscuit fuzzystrmatch |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.5.0 | 1817161514 | pg_textsearch | - |
| RPM | PIGSTY | 0.5.0 | 1817161514 | pg_textsearch_$v | - |
| DEB | PIGSTY | 0.5.0 | 1817161514 | postgresql-$v-textsearch | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.5.0 el8.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.5.0 el8.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el8.aarch64 | PIGSTY 0.5.0 el8.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.5.0 el8.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el9.x86_64 | PIGSTY 0.5.0 el9.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.5.0 el9.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el9.aarch64 | PIGSTY 0.5.0 el9.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.5.0 el9.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el10.x86_64 | PIGSTY 0.5.0 el10.x86_64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.5.0 el10.x86_64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY 0.5.0 el10.aarch64.pg18 : pg_textsearch_18 pg_textsearch_18-0.5.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.5.0 el10.aarch64.pg17 : pg_textsearch_17 pg_textsearch_17-0.5.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 0.5.0 d12.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.5.0 d12.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d12.aarch64 | PIGSTY 0.5.0 d12.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.5.0 d12.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d13.x86_64 | PIGSTY 0.5.0 d13.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.5.0 d13.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY 0.5.0 d13.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.5.0 d13.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 0.5.0 u22.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.5.0 u22.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u22.aarch64 | PIGSTY 0.5.0 u22.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.5.0 u22.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u24.x86_64 | PIGSTY 0.5.0 u24.x86_64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
| PIGSTY 0.5.0 u24.x86_64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
| PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u24.aarch64 | PIGSTY 0.5.0 u24.aarch64.pg18 : postgresql-18-textsearch postgresql-18-textsearch_0.5.0-1PIGSTY~noble_arm64.deb
| PIGSTY 0.5.0 u24.aarch64.pg17 : postgresql-17-textsearch postgresql-17-textsearch_0.5.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
Create Extension:
CREATE EXTENSION pg_textsearch;
Usage
pg_textsearch: Modern ranked text search for PostgreSQL with BM25
Modern ranked text search using BM25 scoring with Block-Max WAND optimization. Simple syntax, fast top-k queries, parallel index builds, and partitioned table support.
Add to shared_preload_libraries:
shared_preload_libraries = 'pg_textsearch'
CREATE EXTENSION pg_textsearch;
Quick Start
CREATE TABLE documents (id bigserial PRIMARY KEY, content text);
INSERT INTO documents (content) VALUES
('PostgreSQL is a powerful database system'),
('BM25 is an effective ranking function'),
('Full text search with custom scoring');
-- Create a BM25 index
CREATE INDEX docs_idx ON documents USING bm25(content) WITH (text_config='english');
-- Query using the <@> operator (returns negative BM25 score, lower = better match)
SELECT * FROM documents
ORDER BY content <@> 'database system'
LIMIT 5;
Querying
-- Auto-detect index from column
SELECT * FROM documents
ORDER BY content <@> 'database system'
LIMIT 5;
-- Explicit index specification
SELECT * FROM documents
WHERE content <@> to_bm25query('database system', 'docs_idx') < -1.0;
Filtering
Pre-filtering reduces rows before scoring (best with selective filters):
CREATE INDEX ON documents (category_id);
SELECT * FROM documents
WHERE category_id = 123
ORDER BY content <@> 'search terms'
LIMIT 10;
Post-filtering applies BM25 scan first, then filters:
SELECT * FROM documents
WHERE content <@> to_bm25query('search terms', 'docs_idx') < -5.0
ORDER BY content <@> 'search terms'
LIMIT 10;
Index Options
| Option | Default | Description |
|---|---|---|
text_config | (required) | PostgreSQL text search configuration |
k1 | 1.2 | Term frequency saturation parameter |
b | 0.75 | Length normalization parameter |
CREATE INDEX ON documents USING bm25(content)
WITH (text_config='english', k1=1.5, b=0.8);
-- Language-specific configurations
CREATE INDEX ON french_docs USING bm25(content) WITH (text_config='french');
CREATE INDEX ON german_docs USING bm25(content) WITH (text_config='german');
Data Types
bm25query — represents queries for BM25 scoring:
SELECT to_bm25query('search query text', 'docs_idx');
-- docs_idx:search query text
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.