pg_textsearch

pg_textsearch

pg_textsearch : Full-text search with BM25 ranking

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2180
pg_textsearch
pg_textsearch
0.5.0
FTS
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_search
pgroonga
pg_bigm
zhparser
pg_trgm
rum
biscuit
fuzzystrmatch

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.5.0
18
17
16
15
14
pg_textsearch-
RPM
PIGSTY
0.5.0
18
17
16
15
14
pg_textsearch_$v-
DEB
PIGSTY
0.5.0
18
17
16
15
14
postgresql-$v-textsearch-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
el8.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
el9.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
el9.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
el10.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
el10.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
d12.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
d12.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
d13.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
d13.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
u22.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
u22.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
u24.x86_64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
u24.aarch64
PIGSTY 0.5.0
PIGSTY 0.5.0
MISS
MISS
MISS
PackageVersionOSORGSIZEFile URL
pg_textsearch_180.5.0el8.x86_64pigsty100.9 KiBpg_textsearch_18-0.5.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_180.5.0el8.aarch64pigsty96.4 KiBpg_textsearch_18-0.5.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_180.5.0el9.x86_64pigsty92.6 KiBpg_textsearch_18-0.5.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_180.5.0el9.aarch64pigsty89.8 KiBpg_textsearch_18-0.5.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_180.5.0el10.x86_64pigsty95.8 KiBpg_textsearch_18-0.5.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_180.5.0el10.aarch64pigsty92.0 KiBpg_textsearch_18-0.5.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-textsearch0.5.0d12.x86_64pigsty831.3 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-textsearch0.5.0d12.aarch64pigsty824.4 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-textsearch0.5.0d13.x86_64pigsty832.8 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
postgresql-18-textsearch0.5.0d13.aarch64pigsty825.7 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
postgresql-18-textsearch0.5.0u22.x86_64pigsty919.9 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
postgresql-18-textsearch0.5.0u22.aarch64pigsty918.7 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
postgresql-18-textsearch0.5.0u24.x86_64pigsty887.0 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
postgresql-18-textsearch0.5.0u24.aarch64pigsty882.4 KiBpostgresql-18-textsearch_0.5.0-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_textsearch_170.5.0el8.x86_64pigsty100.8 KiBpg_textsearch_17-0.5.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_170.5.0el8.aarch64pigsty96.2 KiBpg_textsearch_17-0.5.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_170.5.0el9.x86_64pigsty92.5 KiBpg_textsearch_17-0.5.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_170.5.0el9.aarch64pigsty89.7 KiBpg_textsearch_17-0.5.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_170.5.0el10.x86_64pigsty95.6 KiBpg_textsearch_17-0.5.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_170.5.0el10.aarch64pigsty91.9 KiBpg_textsearch_17-0.5.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-textsearch0.5.0d12.x86_64pigsty822.1 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-textsearch0.5.0d12.aarch64pigsty814.3 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-textsearch0.5.0d13.x86_64pigsty822.2 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
postgresql-17-textsearch0.5.0d13.aarch64pigsty814.9 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
postgresql-17-textsearch0.5.0u22.x86_64pigsty963.6 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
postgresql-17-textsearch0.5.0u22.aarch64pigsty960.4 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
postgresql-17-textsearch0.5.0u24.x86_64pigsty872.9 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
postgresql-17-textsearch0.5.0u24.aarch64pigsty869.8 KiBpostgresql-17-textsearch_0.5.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_textsearch;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_textsearch;		# install via package name, for the active PG version

pig install pg_textsearch -v 18;   # install for PG 18
pig install pg_textsearch -v 17;   # install for PG 17

Create this extension with:

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

OptionDefaultDescription
text_config(required)PostgreSQL text search configuration
k11.2Term frequency saturation parameter
b0.75Length 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
Last updated on