EPiServer Find Sample

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

Highlighting Search listing with keyword highlighting

Try searching for "city center", "golf" or "luxury" and look at for those words in the search results.

View Source
var results = client.Search<Hotel>()
    .For(q)
    .Select(x => new SearchHit
    {
        Title = !string.IsNullOrEmpty(x.Name.AsHighlighted()) ? x.Name.AsHighlighted() : x.Name,
        Url = x.Website,
        Location = new List<string> { x.ShortAddress, x.Location.Title, x.Location.Country.Title }.Concatenate(", "),
        StarRating = x.StarRating,
        Text = x.Description.AsHighlighted(
            new HighlightSpec
            {
                FragmentSize = 200, 
                NumberOfFragments = 2,
                Concatenation = highlights => highlights.Concatenate(" ... ")
            })
    })
    .GetResult();