EPiServer Find Sample

  • Basic
  • Sorting
  • Paging
  • Highlighting
  • Filters
  • Facets
  • Autocomplete
  • Map

Sorting Basic search with sorting

Try an empty search or searching for "hotel" to get many hits and use the links at the top of the search results to change sorting.

View Source
ITypeSearch<Hotel> query = client.Search<Hotel>().For(q);

switch (sort)
{
    case "name":
        query = query.OrderBy(x => x.Name);
        break;
    case "chain":
        query = query.OrderBy(x => x.Chain);
        break;
    case "country":
        query = query.OrderBy(x => x.Location.Country.Title);
        break;
    case "rating":
        query = query.OrderByDescending(x => x.StarRating);
        break;
}

var results = query.Select(x => new SearchHit
                            {
                                Title = x.Name,
                                Url = x.Website,
                                Location = new List { x.ShortAddress, x.Location.Title, x.Location.Country.Title }.Concatenate(", "),
                                StarRating = (int) x.StarRating
                            })
    .GetResult();