Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

How it works

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

Example:

C#
client.Search<Article>()
    .OrderBy(x => x.PublicationDate)
    .ThenBy(x => x.Author.Name)

Sorting is supported for numerical types such as int, double, DateTime, and string.

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. For all types except string, you can change this behavior by supplying a second parameter of the SortMissing enum type.

C#
client.Search<Article>()
    .OrderBy(x => x.PublicationDate, SortMissing.Last)

Sorting by geographical distance

The OrderBy and OrderByDescending methods have an overload for ordering by geographical distance for fields of type GeoLocation. For more information, see Geo Search.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Nov 16, 2015

Recommended reading