Put Custom Sorter (Server-Wide) Operation


  • 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 PutServerWideSortersOperation to deploy a custom sorter to the RavenDB server.
    Once deployed, you can use it to sort query results for all queries made on all databases in your cluster.

  • To deploy a custom sorter that will apply only to the database scoped to your Document Store,
    see put custom sorter.

  • A custom sorter can also be uploaded server-wide from the Studio.

  • In this page:


Put custom sorter server-wide

  • First, create your own sorter class that inherits from the Lucene class Lucene.Net.Search.FieldComparator.

  • Then, send the custom sorter to the server using the PutServerWideSortersOperation.

// Create the sorter definition object
const 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 (C# code)
    code: "<code of custom sorter>"
};

// Define the put sorters operation, pass the sorter definition
const putSortersServerWideOp = new PutServerWideSortersOperation(sorterDefinition);

// Execute the operation by passing it to maintenance.server.send
await documentStore.maintenance.server.send(putSortersServerWideOp );

You can now order your query results using the custom sorter.
A query example is available here.

Syntax

const putSortersServerWideOp = new PutServerWideSortersOperation(sortersToAdd);
Parameter Type Description
sortersToAdd ...object[] One or more Sorter Definitions to send to the server

// The sorter definition object 
{
    name: string;
    code: string;
}