Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ public class SearchResultViewModel
/// Gets or sets the catalogue result paging.
/// </summary>
public PagingViewModel CatalogueResultPaging { get; set; }

/// <summary>
/// Gets or sets a value indicating whether Did You Mean Enabled or not.
/// </summary>
public bool DidYouMeanEnabled { get; set; }
}
}
32 changes: 32 additions & 0 deletions LearningHub.Nhs.WebUI/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Http;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using HtmlAgilityPack;
Expand Down Expand Up @@ -61,6 +62,7 @@
var searchSortItemList = SearchHelper.GetSearchSortList();
var selectedSortItem = searchSortItemList.Where(x => x.SearchSortType == (SearchSortTypeEnum)searchSortType).FirstOrDefault();
var groupId = Guid.Parse(searchRequest.GroupId);
bool didYouMeanEnabled = false;

var resourceSearchPageSize = this.settings.FindwiseSettings.ResourceSearchPageSize;
var catalogueSearchPageSize = this.settings.FindwiseSettings.CatalogueSearchPageSize;
Expand Down Expand Up @@ -112,6 +114,35 @@

resourceResult = resourceResultTask.Result;
catalogueResult = catalogueResultTask.Result;

// Did you mean suggestion when no hits found
if (resourceResult?.TotalHits == 0 && catalogueResult?.TotalHits == 0 && (resourceResult?.Spell?.Suggestions?.Count > 0 || catalogueResult?.Spell?.Suggestions?.Count > 0))

Check failure on line 119 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 119 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchCatalogueViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchCatalogueViewModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 119 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 119 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchCatalogueViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchCatalogueViewModel' could be found (are you missing a using directive or an assembly reference?)
{
didYouMeanEnabled = true;

// pass the spell suggestion as new search text - resources
if (resourceResult?.Spell?.Suggestions?.Count > 0)

Check failure on line 124 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 124 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)
{
resourceSearchRequestModel.SearchText = Regex.Replace(resourceResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);

Check failure on line 126 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 126 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchViewModel' could be found (are you missing a using directive or an assembly reference?)

// calling findwise endpoint with new search text - resources
resourceResultTask = this.GetSearchResultAsync(resourceSearchRequestModel);
}

// pass the spell suggestion as new search text - catalogues
if (catalogueResult?.Spell?.Suggestions?.Count > 0)

Check failure on line 133 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchCatalogueViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchCatalogueViewModel' could be found (are you missing a using directive or an assembly reference?)
{
catalogueSearchRequestModel.SearchText = Regex.Replace(catalogueResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);

Check failure on line 135 in LearningHub.Nhs.WebUI/Services/SearchService.cs

View workflow job for this annotation

GitHub Actions / Build and test

'SearchCatalogueViewModel' does not contain a definition for 'Spell' and no accessible extension method 'Spell' accepting a first argument of type 'SearchCatalogueViewModel' could be found (are you missing a using directive or an assembly reference?)

// calling findwise endpoint with new search text - catalogues
catalogueResultTask = this.GetCatalogueSearchResultAsync(catalogueSearchRequestModel);
}

await Task.WhenAll(resourceResultTask, catalogueResultTask);

resourceResult = resourceResultTask.Result;
catalogueResult = catalogueResultTask.Result;
}
}

var searchfilters = new List<SearchFilterModel>();
Expand Down Expand Up @@ -198,6 +229,7 @@
PageSize = catalogueSearchPageSize,
TotalItems = catalogueResult?.TotalHits ?? 0,
},
DidYouMeanEnabled = didYouMeanEnabled,
};

return searchResultViewModel;
Expand Down
6 changes: 6 additions & 0 deletions LearningHub.Nhs.WebUI/Views/Search/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<h1 class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
Search results @(!string.IsNullOrEmpty(Model.SearchString) ? "for " + Model.SearchString : string.Empty)
</h1>
@if (Model.DidYouMeanEnabled)
{
<h6 class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
We couldn't find a match for <em>@(Model.SearchString)</em>, try adjusting your search terms or explore the suggestions below.
</h6>
}

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
Expand Down
2 changes: 2 additions & 0 deletions WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private async Task<SearchViewModel> GetSearchResults(SearchRequestModel searchRe

searchViewModel.Feedback = results.Feedback;
searchViewModel.RelatedCatalogues = await this.catalogueService.GetCatalogues(catalogueIds);
searchViewModel.Spell = results.Spell;

return searchViewModel;
}
Expand Down Expand Up @@ -390,6 +391,7 @@ private async Task<SearchCatalogueViewModel> GetCatalogueSearchResults(Catalogue

searchViewModel.SearchId = catalogueSearchRequestModel.SearchId > 0 ? catalogueSearchRequestModel.SearchId : results.SearchId;
searchViewModel.Feedback = results.Feedback;
searchViewModel.Spell = results.Spell;

return searchViewModel;
}
Expand Down
Loading