pg_textsearch

pg_textsearch

pg_textsearch : Full-text search with BM25 ranking

Overview

ID Extension Package Version Category License Language
2180
pg_textsearch
pg_textsearch
1.0.0
FTS
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
See Also
pg_search
pgroonga
pg_bigm
zhparser
pg_trgm
rum
biscuit
fuzzystrmatch

bm25 am conflicts with pg_search; must be preloaded via shared_preload_libraries.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.0.0
18
17
16
15
14
pg_textsearch -
RPM
PIGSTY
1.0.0
18
17
16
15
14
pg_textsearch_$v -
DEB
PIGSTY
1.0.0
18
17
16
15
14
postgresql-$v-textsearch -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
el8.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
el9.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
el9.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
el10.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
el10.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
d12.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
d12.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
d13.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
d13.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
u22.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
u22.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
u24.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
u24.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
MISS
MISS
MISS
Package Version OS ORG SIZE File URL
pg_textsearch_18 1.0.0 el8.x86_64 pigsty 110.6 KiB pg_textsearch_18-1.0.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_18 1.0.0 el8.aarch64 pigsty 105.3 KiB pg_textsearch_18-1.0.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_18 1.0.0 el9.x86_64 pigsty 101.9 KiB pg_textsearch_18-1.0.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_18 1.0.0 el9.aarch64 pigsty 99.3 KiB pg_textsearch_18-1.0.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_18 1.0.0 el10.x86_64 pigsty 105.1 KiB pg_textsearch_18-1.0.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_18 1.0.0 el10.aarch64 pigsty 100.7 KiB pg_textsearch_18-1.0.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-textsearch 1.0.0 d12.x86_64 pigsty 894.9 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-textsearch 1.0.0 d12.aarch64 pigsty 887.0 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-textsearch 1.0.0 d13.x86_64 pigsty 895.9 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-18-textsearch 1.0.0 d13.aarch64 pigsty 888.3 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-18-textsearch 1.0.0 u22.x86_64 pigsty 991.8 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~jammy_amd64.deb
postgresql-18-textsearch 1.0.0 u22.aarch64 pigsty 990.0 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~jammy_arm64.deb
postgresql-18-textsearch 1.0.0 u24.x86_64 pigsty 953.6 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~noble_amd64.deb
postgresql-18-textsearch 1.0.0 u24.aarch64 pigsty 949.3 KiB postgresql-18-textsearch_1.0.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_textsearch_17 1.0.0 el8.x86_64 pigsty 110.5 KiB pg_textsearch_17-1.0.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_17 1.0.0 el8.aarch64 pigsty 105.1 KiB pg_textsearch_17-1.0.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_17 1.0.0 el9.x86_64 pigsty 101.8 KiB pg_textsearch_17-1.0.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_17 1.0.0 el9.aarch64 pigsty 99.0 KiB pg_textsearch_17-1.0.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_17 1.0.0 el10.x86_64 pigsty 104.9 KiB pg_textsearch_17-1.0.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_17 1.0.0 el10.aarch64 pigsty 100.6 KiB pg_textsearch_17-1.0.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-textsearch 1.0.0 d12.x86_64 pigsty 881.3 KiB postgresql-17-textsearch_1.0.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-textsearch 1.0.0 d12.aarch64 pigsty 874.8 KiB postgresql-17-textsearch_1.0.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-textsearch 1.0.0 d13.x86_64 pigsty 881.6 KiB postgresql-17-textsearch_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-17-textsearch 1.0.0 d13.aarch64 pigsty 876.6 KiB postgresql-17-textsearch_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-17-textsearch 1.0.0 u22.x86_64 pigsty 1.0 MiB postgresql-17-textsearch_1.0.0-1PIGSTY~jammy_amd64.deb
postgresql-17-textsearch 1.0.0 u22.aarch64 pigsty 1.0 MiB postgresql-17-textsearch_1.0.0-1PIGSTY~jammy_arm64.deb
postgresql-17-textsearch 1.0.0 u24.x86_64 pigsty 942.8 KiB postgresql-17-textsearch_1.0.0-1PIGSTY~noble_amd64.deb
postgresql-17-textsearch 1.0.0 u24.aarch64 pigsty 938.6 KiB postgresql-17-textsearch_1.0.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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_textsearch';

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

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
Last updated on