Website search example 1
A code example for frontend search code that searches for the specific text in all the documents that have a URL assigned to them (once that have to be visible on frontend):
public class SearchResultEntry { public string Label { get; set; } public string Description { get; set; } public string Url { get; set; } } public class SearchResult { public ICollection<SearchResultEntry> Documents { get; set; } public int TotalDocumentsFound { get; set; } } public static class FrontendSearch { public static async Task<SearchResult> SearchAsync(CultureInfo culture, string text, int pageSize, int pageNumber) { var searchQuery = new SearchQuery(text, culture) { MaxDocumentsNumber = pageSize, SearchResultOffset = pageNumber * pageSize }; searchQuery.ShowOnlyDocumentsWithUrls(); var result = await SearchFacade.SearchProvider.SearchAsync(searchQuery); return new SearchResult { Documents = result.Documents.Select(ToSearchResultLine).Evaluate(), TotalDocumentsFound = result.TotalHits }; } private static SearchResultEntry ToSearchResultLine(SearchDocument doc) { object desc; doc.FieldValues.TryGetValue(DefaultDocumentFieldNames.Description, out desc); return new SearchResultEntry { Label = doc.Label, Description = desc as string, Url = doc.Url }; } }