---
title: "Put Custom Sorter Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/sorters/put-sorter"
version: "6.2"
language: "csharp"
---

# Put Custom Sorter Operation

> Client language: C#. Also available for [Node.js](https://docs.ravendb.net/6.2/client-api/operations/maintenance/sorters/put-sorter.nodejs.md).
>
> 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."

> **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.
>
> - Use `PutSortersOperation` to deploy a custom sorter to the RavenDB server.  
>   Once deployed, you can use it to sort query results for all queries made on the **database**  
>   that is scoped to your [Document Store](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.md).
>
> - To deploy a custom sorter that will apply cluster-wide, to all databases, see [put server-wide sorter](https://docs.ravendb.net/6.2/client-api/operations/server-wide/sorters/put-sorter-server-wide.md).
>
> - A custom sorter can also be uploaded to the server from the [Studio](https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters.md).
>
> - In this page:
>   - [Put custom sorter](#put-custom-sorter)
>   - [Syntax](#syntax)

## Put custom sorter

- First, create your own sorter class that inherits from the Lucene class [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).

- Then, send the custom sorter to the server using the `PutSortersOperation`.

### Sync

```csharp
// Assign the code of your custom sorter as a `string`
string mySorterCode = "<code of custom sorter>";

// Create the `SorterDefinition` object
var customSorterDefinition = new SorterDefinition
{
  // The sorter Name must be the same as the sorter's class name in your code
  Name = "MySorter",
  // The Code must be compilable and include all necessary using statements
  Code = mySorterCode
};

// Define the put sorters operation, pass the sorter definition
// Note: multiple sorters can be passed, see syntax below
var putSortersOp = new PutSortersOperation(customSorterDefinition);

// Execute the operation by passing it to Maintenance.Send
store.Maintenance.Send(putSortersOp);
```

### Async

```csharp
// Assign the code of your custom sorter as a `string`
string mySorterCode = "<code of custom sorter>";

// Create the `SorterDefinition` object
var customSorterDefinition = new SorterDefinition
{
  // The sorter Name must be the same as the sorter's class name in your code
  Name = "MySorter",
  // The Code must be compilable and include all necessary using statements
  Code = mySorterCode
};

// Define the put sorters operation, pass the sorter definition
// Note: multiple sorters can be passed, see syntax below
var putSortersOp = new PutSortersOperation(customSorterDefinition);

// Execute the operation by passing it to Maintenance.SendAsync
await store.Maintenance.SendAsync(putSortersOp);
```

> **Note**
>
> You can now 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).

## Syntax

```csharp
public PutSortersOperation(params SorterDefinition[] sortersToAdd)
```

| Parameter | Type | Description |
| - | - | - |
| **sortersToAdd** | `SorterDefinition[]` | One or more Sorter Definitions to send to the server |

```csharp
public class SorterDefinition
{
  public string Name { get; set; }
  public string Code { get; set; }
}
```

## See also

- [Sort query results](https://docs.ravendb.net/6.2/client-api/session/querying/sort-query-results.md)
- [What are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.md)
- [Put server-wide sorter](https://docs.ravendb.net/6.2/client-api/operations/server-wide/sorters/put-sorter-server-wide.md)
- [Custom sorters view](https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters.md)
