Keyword search
A blog or knowledge base needs to locate records containing one or more terms in a text column.
Prisma · Const
Prisma Client’s search filter performs database-native full-text search on String fields. It supports MySQL and PostgreSQL, with PostgreSQL requiring the fullTextSearchPostgres preview feature.
The search filter performs full-text search against a String field through the database’s native search support. In Prisma ORM v7, MySQL supports it directly, while PostgreSQL requires the fullTextSearchPostgres preview feature before the generated client exposes the filter.
{ where: { <stringField>: { search: <query> } } }| Name | Type | Description |
|---|---|---|
search | string | A full-text search expression, such as cat, cat | dog, or cat & dog. |
A Prisma Client query result containing records whose searched String field matches the full-text expression.
search filter is available for MySQL and PostgreSQL, with PostgreSQL requiring its preview feature.search filter to generated types for eligible String fields.const result = await prisma.post.findMany({
where: {
title: {
search: "cat | dog",
},
},
});Searches post titles for either “cat” or “dog” with Prisma Client.
A blog or knowledge base needs to locate records containing one or more terms in a text column.
A MySQL application needs native text matching rather than loading rows and filtering them in application code.
A PostgreSQL application wants Prisma-generated types for full-text search during preview adoption.
Use the search property inside a String field’s filter, for example title: { search: "cat | dog" }. Prisma translates the operation to the database’s native full-text search support.
Follow-up: How would PostgreSQL support be enabled? Add fullTextSearchPostgres to the schema’s preview features, then regenerate Prisma Client.
The search expression supports operators such as | for alternatives and & for terms that must both occur. The result is obtained through a normal Prisma Client query such as findMany().
Follow-up: What must be configured for MySQL? Add a @@fulltext index for each searched column.
PostgreSQL support is preview-only in the current documentation, so the fullTextSearchPostgres feature flag must be enabled before using the generated search field. MySQL support is documented without that PostgreSQL preview requirement.
Follow-up: Why does the database index matter? Native full-text search can use the declared index for efficient lookup.
Prisma ClientfullTextSearchPostgres@@fulltextfindMany()String