Put Custom Sorter 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 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.

  • To deploy a custom sorter that will apply cluster-wide, to all databases, see put server-wide sorter.

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

  • In this page:


Put custom sorter

  • 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 PutSortersOperation.

// 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 putSorterOp = new PutSortersOperation(sorterDefinition);

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

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

Syntax

const putSorterOp = new PutSortersOperation(sortersToAdd);
Parameter Type Description
sortersToAdd ...object[] One or more Sorter Definition objects to send to the server

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