{"name":"pg_textsearch: Modern BM25 Full-Text Search for PostgreSQL","description":"pg_textsearch is a powerful PostgreSQL extension that brings modern BM25 relevance-ranked full-text search capabilities directly to your database. It offers a simple syntax, configurable parameters, and integrates seamlessly with existing PostgreSQL text search configurations. This extension provides best-in-class performance and scalability for your search needs.","github":"https://github.com/timescale/pg_textsearch","url":"https://osrepos.com/repo/timescale-pg_textsearch","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/timescale-pg_textsearch","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/timescale-pg_textsearch.md","json":"https://osrepos.com/repo/timescale-pg_textsearch.json","topics":["bm25","c-extension","full-text-search","postgresql","database","search-engine"],"keywords":["bm25","c-extension","full-text-search","postgresql","database","search-engine"],"stars":null,"summary":"pg_textsearch is a powerful PostgreSQL extension that brings modern BM25 relevance-ranked full-text search capabilities directly to your database. It offers a simple syntax, configurable parameters, and integrates seamlessly with existing PostgreSQL text search configurations. This extension provides best-in-class performance and scalability for your search needs.","content":"## Introduction\n`pg_textsearch` is a PostgreSQL extension developed by Timescale that provides advanced full-text search functionality using the BM25 ranking algorithm. This extension allows developers to implement highly relevant search experiences directly within their PostgreSQL databases, leveraging the power of a proven ranking function. It's designed for performance and scalability, making it suitable for a wide range of applications requiring sophisticated text search. The project, originally named Tapir, maintains its mascot and is currently production-ready at v1.4.0-dev, supporting PostgreSQL 17 and 18.\n\n## Installation\nGetting `pg_textsearch` up and running is straightforward. You can either use pre-built binaries or compile it from source.\n\n### Pre-built Binaries:\nDownload the appropriate binaries for your system (Linux or macOS, amd64 or arm64) and PostgreSQL version (17 or 18) from the official [Releases page](https://github.com/timescale/pg_textsearch/releases).\n\n### Build from Source:\nFor those who prefer to build from source, follow these steps:\nsh\ncd /tmp\ngit clone https://github.com/timescale/pg_textsearch\ncd pg_textsearch\nmake\nmake install # may need sudo\n\nIf you have multiple PostgreSQL installations, specify `PG_CONFIG`:\nsh\nexport PG_CONFIG=/path/to/your/pg_config\nmake clean && make && make install\n\nOn Debian/Ubuntu, you might need to install development files:\nsh\nsudo apt install postgresql-server-dev-17 # for PostgreSQL 17\nsudo apt install postgresql-server-dev-18 # for PostgreSQL 18\n\n\n### Enable the Extension:\nAfter installation, you need to load the extension in your `postgresql.conf` and then enable it in your database:\n1.  Add `pg_textsearch` to `shared_preload_libraries` in `postgresql.conf` and restart your server:\n    \n    shared_preload_libraries = 'pg_textsearch'  # add to existing list if needed\n    \n2.  Enable the extension in your database:\n    sql\n    CREATE EXTENSION pg_textsearch;\n    \n\n## Examples\nHere's how to get started with `pg_textsearch` for basic full-text search.\n\n### Basic Search:\n1.  Create a table with text content:\n    sql\n    CREATE TABLE documents (id bigserial PRIMARY KEY, content text);\n    INSERT INTO documents (content) VALUES\n        ('PostgreSQL is a powerful database system'),\n        ('BM25 is an effective ranking function'),\n        ('Full text search with custom scoring');\n    \n2.  Create a `pg_textsearch` index on the text column, specifying a text configuration (e.g., 'english'):\n    sql\n    CREATE INDEX docs_idx ON documents USING bm25(content) WITH (text_config='english');\n    \n3.  Query for relevant documents using the `<@>` operator. Note that lower scores indicate better matches.\n    sql\n    SELECT * FROM documents\n    ORDER BY content <@> 'database system'\n    LIMIT 5;\n    \n    For explicit index specification, use `to_bm25query`:\n    sql\n    SELECT * FROM documents\n    ORDER BY content <@> to_bm25query('database system', 'docs_idx')\n    LIMIT 5;\n    \n\n### Expression Indexes:\nYou can also create indexes on expressions, useful for JSONB fields or multi-column searches:\nsql\n-- Indexing a JSONB field\nCREATE INDEX ON events USING bm25 ((data->>'description'))\n    WITH (text_config='english');\n\n-- Querying the JSONB field\nSELECT * FROM events\nORDER BY (data->>'description') <@> to_bm25query('network error', 'events_expr_idx')\nLIMIT 10;\n\n\n## Why Use `pg_textsearch`?\n`pg_textsearch` offers several compelling reasons for integrating it into your PostgreSQL-based applications:\n*   **BM25 Ranking:** It provides the industry-standard BM25 ranking algorithm, delivering highly relevant search results based on term frequency and document length normalization.\n*   **Simple Integration:** With a straightforward SQL syntax and seamless integration with PostgreSQL's native text search configurations, it's easy to adopt.\n*   **Performance and Scalability:** Designed for efficiency, it supports fast top-k queries via Block-Max WAND optimization, parallel index builds, and an optimized memtable architecture for writes.\n*   **Flexibility:** Supports expression indexes for complex data types like JSONB, partial indexes for scoped searches, and multilingual tables, allowing for highly customized search solutions.\n*   **PostgreSQL Native:** Being a PostgreSQL extension, it benefits from PostgreSQL's robustness, transactional guarantees, and familiar administration.\n\n## Links\n*   **GitHub Repository:** [https://github.com/timescale/pg_textsearch](https://github.com/timescale/pg_textsearch)\n*   **Releases Page:** [https://github.com/timescale/pg_textsearch/releases](https://github.com/timescale/pg_textsearch/releases)\n*   **Contributing Guidelines:** [https://github.com/timescale/pg_textsearch/blob/main/CONTRIBUTING.md](https://github.com/timescale/pg_textsearch/blob/main/CONTRIBUTING.md)","metrics":{"detailViews":4,"githubClicks":2},"dates":{"published":null,"modified":"2026-06-12T20:55:29.000Z"}}