# Full-Text Search

Build powerful search features with native full-text search, ranking, highlighting, and fuzzy matching.

## Overview

Prax provides a unified API for full-text search across all supported databases, from PostgreSQL's powerful tsvector to MongoDB Atlas Search.

Feature | PostgreSQL | MySQL | SQLite | MSSQL | MongoDB
--- | --- | --- | --- | --- | ---
Full-Text Index | ✅ tsvector/GIN | ✅ FULLTEXT | ✅ FTS5 | ✅ Full-Text | ✅ Atlas Search
Relevance Ranking | ✅ ts_rank | ✅ | ✅ bm25 | ✅ RANK | ✅ score
Highlighting | ✅ ts_headline | ❌ | ✅ | ❌ | ✅
Fuzzy Search | ✅ pg_trgm | ❌ | ❌ | ✅ SOUNDEX | ✅
Faceted Search | ✅ | ❌ | ❌ | ❌ | ✅

## Basic Search

Use `SearchQuery` for simple text search.

## Relevance Ranking

Weight columns differently and sort by relevance score.

## Search Highlighting

Show users where their search terms matched in the results.

## Fuzzy Search

Handle typos and spelling variations with fuzzy matching.

## Phrase & Boolean Search

Search for exact phrases or use boolean operators.

## Creating Search Indexes

Full-text search requires proper indexes for performance.

## MongoDB Atlas Search

Powerful full-text search with Atlas Search, including facets, fuzzy matching, and scoring.

Note: Atlas Search requires MongoDB Atlas (not available on self-hosted). Create indexes in the Atlas UI or via the Admin API.

## Schema & Migrations

Define full-text indexes in your schema and migrations.

## Best Practices

#### Use GIN Indexes (PostgreSQL)

GIN indexes are faster for lookups but slower to update. Use GiST indexes if you have frequent writes and can tolerate slower searches.

#### Pre-compute tsvector

Store a computed tsvector column instead of generating it at query time. Update it via triggers when the source columns change.

#### Limit Result Sets

Full-text search can return many results. Always use LIMIT and implement pagination to avoid performance issues.

#### Consider External Search

For complex search requirements, consider Elasticsearch, Meilisearch, or Typesense. Database full-text search is great for basic to moderate needs.