whatisgithub

What is pg_textsearch?

timescale/pg_textsearch — explained in plain English

Analysis updated 2026-07-03

3,736CAudience · developerComplexity · 3/5LicenseSetup · moderate

In one sentence

pg_textsearch is a PostgreSQL extension that adds BM25 full-text search ranking so your search results come back ordered by relevance, not random order, using plain SQL.

Mindmap

mindmap
  root((pg_textsearch))
    What it does
      BM25 ranking
      Full-text search
      SQL operator
    Tech Stack
      C extension
      PostgreSQL 17-18
      SQL
    Use Cases
      Ranked search results
      JSON field search
      Multilingual indexes
    Audience
      Backend developers
      Database engineers
    Performance
      Block-Max WAND
      Parallel index build
      Partition support
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add relevance-ranked full-text search to a Postgres app so users see the most matching results first instead of arbitrary order

USE CASE 2

Index a JSON column in Postgres and rank search results by BM25 score using a single SQL ORDER BY clause

USE CASE 3

Create separate language-specific search indexes on the same table to serve multilingual content with correct ranking

USE CASE 4

Speed up full-text search on a large partitioned Postgres table using parallel index builds and Block-Max WAND optimization

What is it built with?

CPostgreSQLSQL

How does it compare?

timescale/pg_textsearchdekunukem/nintendo_switch_reverse_engineeringibireme/yyjson
Stars3,7363,7343,738
LanguageCCC
Setup difficultymoderatehardeasy
Complexity3/54/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires PostgreSQL 17 or 18, must be installed as a database extension before use.

Use freely for any purpose under the PostgreSQL open-source license, one of the most permissive available.

So what is it?

pg_textsearch is a PostgreSQL extension that adds modern full-text search ranking to Postgres databases. It implements BM25, a well-established algorithm for scoring search results by how relevant each document is to a given query. Standard Postgres text search can tell you whether a document matches, but BM25 lets you order results by how closely they match, so the most relevant ones come first rather than in arbitrary order. Using the extension follows normal SQL patterns. You create an index on a text column, then write a query with an ORDER BY clause using a special operator. For example: SELECT * FROM documents ORDER BY content <@> 'database system' LIMIT 5. The extension handles the scoring math. Two tunable parameters, k1 and b, let you adjust how the algorithm weighs term frequency versus document length if the defaults do not suit your data. The extension supports multiple languages because it builds on Postgres's existing text search configurations. English, French, German, and other language configurations all work. You can also create separate indexes for different languages on the same table using partial indexes, each covering only rows tagged with a particular language. Beyond plain text columns, pg_textsearch supports expression indexes. This means you can index fields extracted from JSON data, combinations of multiple columns concatenated together, or text that has been transformed before indexing. Partial indexes cover only a subset of rows based on a condition, which keeps the index smaller and queries faster when searches always target a specific category or status. Performance tuning is built in. The extension uses an optimization called Block-Max WAND internally, which avoids scoring documents that cannot possibly rank in the top results of a given query. Parallel index builds are supported for large tables. Partitioned tables are also supported. pg_textsearch is developed by Timescale, released under the PostgreSQL open-source license, and works with PostgreSQL versions 17 and 18.

Copy-paste prompts

Prompt 1
Show me how to install pg_textsearch, create a BM25 index on a 'documents.content' column, and query the top 5 most relevant results for 'machine learning'.
Prompt 2
How do I tune the BM25 k1 and b parameters in pg_textsearch to get better ranking for short technical documents?
Prompt 3
I store multilingual content in a Postgres table with a 'language' column. Show me how to create separate pg_textsearch indexes for English and French rows using partial indexes.
Prompt 4
How do I use pg_textsearch expression indexes to rank search results from a JSONB column where the searchable text is in a nested field called 'body'?
Prompt 5
Explain how Block-Max WAND optimization in pg_textsearch speeds up queries on tables with millions of rows.

Frequently asked questions

What is pg_textsearch?

pg_textsearch is a PostgreSQL extension that adds BM25 full-text search ranking so your search results come back ordered by relevance, not random order, using plain SQL.

What language is pg_textsearch written in?

Mainly C. The stack also includes C, PostgreSQL, SQL.

What license does pg_textsearch use?

Use freely for any purpose under the PostgreSQL open-source license, one of the most permissive available.

How hard is pg_textsearch to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is pg_textsearch for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.