|
1 | | -using EPiServer.Find; |
2 | | -using EPiServer.Find.Cms; |
3 | 1 | using EPiServer.Web.Mvc; |
4 | 2 | using FindToGraph.Models; |
5 | 3 | using Microsoft.AspNetCore.Mvc; |
6 | 4 | using System.Collections.Generic; |
7 | 5 | using System.Linq; |
| 6 | +using System.Threading.Tasks; |
8 | 7 | using FindToGraph.Extensions; |
| 8 | +using StrawberryShake; |
| 9 | + |
9 | 10 |
|
10 | 11 | namespace FindToGraph.Controllers |
11 | 12 | { |
12 | 13 | public class SearchPageController : PageController<SearchPage> |
13 | 14 | { |
14 | | - private readonly IClient _searchClient; |
| 15 | + private readonly IGraphQLClient _searchClient; |
15 | 16 |
|
16 | | - public SearchPageController(IClient findClient) |
| 17 | + public SearchPageController(IGraphQLClient graphClient) |
17 | 18 | { |
18 | | - _searchClient = findClient; |
| 19 | + _searchClient = graphClient; |
19 | 20 | } |
20 | 21 |
|
21 | | - public IActionResult Index(SearchPage currentPage, string? q) |
| 22 | + public async Task<IActionResult> Index(SearchPage currentPage, string? q) |
22 | 23 | { |
23 | 24 | List<string> results = new List<string>(); |
24 | 25 | if (!string.IsNullOrWhiteSpace(q)) |
25 | 26 | { |
26 | | - var searchResults = _searchClient.Search<ArticlePage>() |
27 | | - .For(q).GetContentResult(); |
28 | | - |
29 | | - results = searchResults.Select(hit => hit.Body?.ToHtmlString().StripParagraphTags() ?? "No content").ToList(); |
| 27 | + var searchResult = await _searchClient.Articles.ExecuteAsync(q); |
| 28 | + searchResult.EnsureNoErrors(); |
| 29 | + var items = searchResult.Data?.ArticlePage?.Items; |
| 30 | + if (items != null) { |
| 31 | + results = items.Select(item => item?.Body?.Html?.StripParagraphTags() ?? "No content").ToList(); |
| 32 | + } |
30 | 33 | } |
| 34 | + |
31 | 35 | ViewBag.Query = q; |
32 | 36 | ViewBag.Results = results; |
33 | 37 | return View(currentPage); |
|
0 commit comments