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
0.5.0
FTS
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_search
pgroonga
pg_bigm
zhparser
pg_trgm
rum
biscuit
fuzzystrmatch

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
Package Version OS ORG SIZE File URL
pg_textsearch_18 0.5.0 el8.x86_64 pigsty 100.9 KiB pg_textsearch_18-0.5.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_18 0.5.0 el8.aarch64 pigsty 96.4 KiB pg_textsearch_18-0.5.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_18 0.5.0 el9.x86_64 pigsty 92.6 KiB pg_textsearch_18-0.5.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_18 0.5.0 el9.aarch64 pigsty 89.8 KiB pg_textsearch_18-0.5.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_18 0.5.0 el10.x86_64 pigsty 95.8 KiB pg_textsearch_18-0.5.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_18 0.5.0 el10.aarch64 pigsty 92.0 KiB pg_textsearch_18-0.5.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-textsearch 0.5.0 d12.x86_64 pigsty 831.3 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-textsearch 0.5.0 d12.aarch64 pigsty 824.4 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-textsearch 0.5.0 d13.x86_64 pigsty 832.8 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
postgresql-18-textsearch 0.5.0 d13.aarch64 pigsty 825.7 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
postgresql-18-textsearch 0.5.0 u22.x86_64 pigsty 919.9 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
postgresql-18-textsearch 0.5.0 u22.aarch64 pigsty 918.7 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
postgresql-18-textsearch 0.5.0 u24.x86_64 pigsty 887.0 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
postgresql-18-textsearch 0.5.0 u24.aarch64 pigsty 882.4 KiB postgresql-18-textsearch_0.5.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_textsearch_17 0.5.0 el8.x86_64 pigsty 100.8 KiB pg_textsearch_17-0.5.0-1PIGSTY.el8.x86_64.rpm
pg_textsearch_17 0.5.0 el8.aarch64 pigsty 96.2 KiB pg_textsearch_17-0.5.0-1PIGSTY.el8.aarch64.rpm
pg_textsearch_17 0.5.0 el9.x86_64 pigsty 92.5 KiB pg_textsearch_17-0.5.0-1PIGSTY.el9.x86_64.rpm
pg_textsearch_17 0.5.0 el9.aarch64 pigsty 89.7 KiB pg_textsearch_17-0.5.0-1PIGSTY.el9.aarch64.rpm
pg_textsearch_17 0.5.0 el10.x86_64 pigsty 95.6 KiB pg_textsearch_17-0.5.0-1PIGSTY.el10.x86_64.rpm
pg_textsearch_17 0.5.0 el10.aarch64 pigsty 91.9 KiB pg_textsearch_17-0.5.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-textsearch 0.5.0 d12.x86_64 pigsty 822.1 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-textsearch 0.5.0 d12.aarch64 pigsty 814.3 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-textsearch 0.5.0 d13.x86_64 pigsty 822.2 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~trixie_amd64.deb
postgresql-17-textsearch 0.5.0 d13.aarch64 pigsty 814.9 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~trixie_arm64.deb
postgresql-17-textsearch 0.5.0 u22.x86_64 pigsty 963.6 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~jammy_amd64.deb
postgresql-17-textsearch 0.5.0 u22.aarch64 pigsty 960.4 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~jammy_arm64.deb
postgresql-17-textsearch 0.5.0 u24.x86_64 pigsty 872.9 KiB postgresql-17-textsearch_0.5.0-1PIGSTY~noble_amd64.deb
postgresql-17-textsearch 0.5.0 u24.aarch64 pigsty 869.8 KiB postgresql-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

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