pg_search extension, providing powerful full-text search capabilities based on BM25 ranking.
The extension is built on the open-source ParadeDB project, a modern Elasticsearch alternative for Postgres. Relyt has enhanced ParadeDB with Write-Ahead Logging (WAL) support for crash recovery, ensuring production-grade reliability and full recoverability of search indexes. Our enhancements are also open-sourced at github.
Key Features
- Real-time Search: Immediate visibility with zero indexing delay
- High Performance: Parallel BM25 index creation and query execution
- ACID Compliance: Full transactional guarantees
- Crash Recovery: WAL-based backup and recovery support
- Custom Tokenization: User-defined tokenizers for different languages and use cases
Quick Start
Step 1: Create a Table and Insert Sample Data
Use the helper function to create a test table with sample data:mock_items table and populates it with sample product data for testing.
Step 2: Create a BM25 Index
Create a full-text search index on the desired columns:key_field parameter specifies the primary key column used for document identification.
Step 3: Query Using the BM25 Index
The@@@ operator is used for full-text search queries.
Basic Search - Single Term
Multiple Terms
Search with Filters
Combine full-text search with structured filters:Step 4: Advanced Search Features
Proximity Search
Use the tilde (~) operator for phrase proximity matching:
~1 allows one word between the search terms.
Highlighting
Highlight matching terms in search results:Relevance Scoring
Retrieve relevance scores for search results:Field Boosting
Apply different weights to search terms using the caret (^) operator:
^2 boosts the importance of matches in the description field by a factor of 2.
Match Function
Use thepgsearch.match() function for more control over search behavior:
For more advanced features including custom tokenizers, aggregations, fuzzy search, hybrid search, and query optimization techniques, please refer to the ParadeDB documentation. Since Relyt ONE’s
pg_search is based on ParadeDB, most features and syntax are fully compatible.