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 

Search results are by default sorted by relevance, given that a search query exists. By using the OrderBy, ThenBy, OrderByDescending and ThenByDescending methods it is possible to instead sort by a specific field.

Example:

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

Sorting is supported on numerical types such as int and double, DateTime and strings.

Null values and SortMissing

By default documents with null values in a field on which the search results are being sorted on will be sorted first when using the OrderBy and ThenBy methods and last when using the OrderByDescending and ThenByDescending methods. For all types except strings this can be changed 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 both have an overload for ordering by geographical distance for fields of type GeoLocation. For more information see the topic for Geo Search.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jun 10, 2014

Recommended reading