---
title: Set the sort order
slug: cms-12/docs/sorting
docTags: 
createdAt: 2026-08-10T15:55:58.000Z
---

By default, search results are sorted by relevance. You can change the sort factor using `OrderBy`, `ThenBy`, `OrderByDescending`, or `ThenByDescending`.

:::hint{type="info"}
**Note**
Relevance is calculated by the Lucene search engine. It is based on several factors, such as: the number of hits in the document, and the location of the search terms in the document. To customize how relevance is calculated, see [Boost search results with filters](docId\:ib6eo-ncasmVKrIDcX6yq) and [Boost search results with weights](docId\:cX_OBfT4KC8a42TOvTrpC).
:::

**Example**

```csharp
client.Search<Article>()
    .OrderBy(x => x.PublicationDate)
    .ThenBy(x => x.Author.Name)
```

Optimizely Search & Navigation supports sorting for numerical types such as `int`, `double`, `DateTime`, and `string`.

:::hint{type="warning"}
**Important**
`OrderBy` must contain less than 50 characters.
:::

## Null values and SortMissing

By default, if a document has a null value in a field used to sort search results, it is sorted *first* when using the `OrderBy` and `ThenBy` methods, and *last* when using the `OrderByDescending` and `ThenByDescending` methods. You can change this behavior by supplying a second parameter of the `SortMissing` `enum` type.

```csharp
client.Search<Article>()
    .OrderBy(x => x.PublicationDate, SortMissing.Last)
    .ThenByDescending(x => x.Author.Name, SortMissing.First)
```

## Sort by geographical distance

The `OrderBy` and `OrderByDescending` methods have an overload for ordering by geographical distance for fields of type `GeoLocation`. See [Geo Search](docId\:YLiwqLEXdzuHUHyT7jlt-).
