Skip to content

Commit

Permalink
Update 050-filtering-and-sorting.mdx (#6464)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk authored Nov 27, 2024
1 parent b3ddcad commit c050161
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ generator client {

Ordering by relevance can be used either separately from or together with the `search` filter: `_relevance` is used to order the list, while `search` filters the unordered list.

For example, the following query uses `_relevance` to filter by the term `developer` in the `bio` field, and then sorts the result by relevance in an ascending manner:
For example, the following query uses `_relevance` to filter by the term `developer` in the `bio` field, and then sorts the result by relevance in a _descending_ manner:

```ts
const getUsersByRelevance = await prisma.user.findMany({
Expand All @@ -410,7 +410,7 @@ const getUsersByRelevance = await prisma.user.findMany({
_relevance: {
fields: ['bio'],
search: 'developer',
sort: 'asc',
sort: 'desc',
},
},
})
Expand All @@ -427,15 +427,15 @@ Prior to Prisma ORM 5.16.0, enabling the `fullTextSearch` preview feature would

### Sort with null records first or last

<Admonition type="info">
:::info

Notes:

- This feature is generally available in version `4.16.0` and later. To use this feature in versions [`4.1.0`](https://github.com/prisma/prisma/releases/tag/4.1.0) to [`4.15.0`](https://github.com/prisma/prisma/releases/tag/4.15.0) the [Preview feature](/orm/reference/preview-features/client-preview-features#enabling-a-prisma-client-preview-feature) `orderByNulls` will need to be enabled.
- This feature is not available for MongoDB.
- You can only sort by nulls on optional [scalar](/orm/prisma-schema/data-model/models#scalar-fields) fields. If you try to sort by nulls on a required or [relation](/orm/prisma-schema/data-model/models#relation-fields) field, Prisma Client throws a [P2009 error](/orm/reference/error-reference#p2009).

</Admonition>
:::

You can sort the results so that records with `null` fields appear either first or last.

Expand Down

0 comments on commit c050161

Please sign in to comment.