Full-text search
Prisma ORM v7Learn how to search text fields with Prisma Client using your database's native full-text search support.
Prisma Client supports full-text search for MySQL and for PostgreSQL with the fullTextSearchPostgres preview feature.
The search filter on this page wraps PostgreSQL's built-in tsvector matching. For results ranked the way a search engine ranks them, Prisma ORM 8 adds BM25 full-text search through the ParadeDB extension: relevance scores, fuzzy matching, phrase and proximity queries, all typed in the query builder, with the pg_search extension and the index installed by migrations Prisma manages.
const posts = await db.orm.public.Post.where((p) => p.body.paradeDbMatch("database search"))
.orderBy((p) => p.id.paradeDbScore().desc())
.limit(10)
.all();See ParadeDB for setup, the index declaration, and the other search operations.
Enabling full-text search for PostgreSQL
Add the preview flag to your generator and re-generate Prisma Client:
generator client {
provider = "prisma-client"
output = "./generated"
previewFeatures = ["fullTextSearchPostgres"]
}bunx prisma generateSearch within a text field
const posts = await prisma.post.findMany({
where: {
body: {
search: "cat | dog",
},
},
});Sort by relevance
Prisma Client also supports relevance-based ordering on supported databases:
const posts = await prisma.post.findMany({
orderBy: {
_relevance: {
fields: ["title"],
search: "database",
sort: "desc",
},
},
});Related pages
- Filtering and sorting
- Prisma Client API reference
- Preview features
- ParadeDB in Prisma ORM 8: BM25 search ranked by relevance
Updated
