---
title: "Custom Sorters"
description: "* The Lucene indexing engine allows you to create your own Custom Sorters"
url: "https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters"
version: "6.2"
---

# Custom Sorters

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

## Custom Sorters

> **Note**
>
> - The Lucene indexing engine allows you to create your own **Custom Sorters**  
>   where you can define how query results will be ordered based on your specific requirements.
>
> - Custom sorters can be defined either at:
>   - the **database level**, where they can only be used with queries on that database
>   - or at the **server-wide level**, where they can be used with queries made on all databases in your cluster.
>
> - If a database custom sorter and a server-wide custom sorter share the same name,  
>   the database custom sorter will be the one used for the query.
>
> - This view lists all custom sorters that were uploaded via the Studio
>   and from the [client API](https://docs.ravendb.net/6.2/client-api/operations/maintenance/sorters/put-sorter.md).
>
> - Once deployed, you can order your query results using the custom sorter.  
>   A query example is available [here](https://docs.ravendb.net/6.2/client-api/session/querying/sort-query-results.md#custom-sorters).
>
> - In this page:
>   - [Database custom sorter view](#database-custom-sorter-view)
>   - [Server-wide custom sorter view](#server-wide-custom-sorter-view)
>   - [Add a custom sorter](#add-a-custom-sorter)
>   - [Test the custom sorter](#test-the-custom-sorter)

## Database custom sorter view

![Figure 1. Database custom sorter view](https://docs.ravendb.net/assets/images/custom-sorter-1-bee70904327e8a248ce0071693572050.png)

> **Note**
>
> 1. Navigate to **Settings > Custom Sorters**.
>
> 2. Click to add a new database custom sorter.  
>    See the sorter edit view [below](#add-a-custom-sorter).
>
> 3. The custom sorters deployed for this **database** are listed here.
>
> 4. Click to test this custom sorter.  
>    See the test view [below](#test-the-custom-sorter).
>
> 5. Click to edit this custom sorter.
>
> 6. Delete the custom sorter.
>
> 7. The custom sorters deployed **server-wide** are listed here.
>
> 8. Follow this link to manage the server-wide custom sorters.

## Server-wide custom sorter view

![Figure 2. Server-wide custom sorter view](https://docs.ravendb.net/assets/images/custom-sorter-2-d0d3c301f3d3c3fe396a6b29298d244c.png)

> **Note**
>
> 1. Navigate to **Manage Server > Server-Wide Sorters**.
>
> 2. Click to add a new server-wide custom sorter.  
>    See the sorter edit view [below](#add-a-custom-sorter).
>
> 3. The custom sorters deployed **server-wide** are listed here.
>
> 4. Click to edit this server-wide custom sorter.
>
> 5. Delete this server-wide custom sorter.

> **Note**
>
> Note:  
> To test a server-wide sorter go to the Custom Sorters View in any database.

## Add a custom sorter

![Figure 3. Add a custom sorter](https://docs.ravendb.net/assets/images/custom-sorter-3-3ad51e274b259fcf0805296a91d2c1ea.png)

> **Note**
>
> 1. Either load the sorter's code from a `*.cs` file or enter the code manually in this editor.
>
> 2. The **sorter name** must be the same as the class name of your sorter.
>
> 3. Replace the sample code in the image with your own implementation.  
>    The **sorter code** must be compilable and include all necessary `using` statements.  
>    The sorter's class should inherit from [Lucene.Net.Search.FieldComparator](https://lucenenet.apache.org/docs/3.0.3/df/d91/class_lucene_1_1_net_1_1_search_1_1_field_comparator.html).
>
> 4. Save your sorter.

## Test the custom sorter

![Figure 4. Test the custom sorter](https://docs.ravendb.net/assets/images/custom-sorter-4-6a3d67189bd6cf7c87eace036728b6b6.png)

> **Note**
>
> 1. Click to open the test view.
>
> 2. Enter an RQL query to test.  
>    To order by your sorter use `order by custom(<field name>, <your sorter name>)`
>
> 3. Click Run test.
