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
|
Source
pig build pkg pg_textsearch; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 17Create 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 textLast updated on