diff --git a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj
index f10d8aaab..0b26b9cd7 100644
--- a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj
+++ b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj
@@ -89,7 +89,7 @@
-
+
diff --git a/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs b/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs
index 477aabfbf..2fca0012e 100644
--- a/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs
+++ b/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
+ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using LearningHub.Nhs.Caching;
using LearningHub.Nhs.Models.Catalogue;
@@ -109,6 +110,28 @@ public async Task Index(int pageIndex = 1, string term = null)
PageSize = itemsOnPage,
});
+ // Did you mean suggestion when no hits found
+ if (termCatalogues?.TotalHits == 0 && termCatalogues?.Spell?.Suggestions?.Count > 0)
+ {
+ // pass the spell suggestion as new search text - catalogues
+ if (termCatalogues?.Spell?.Suggestions?.Count > 0)
+ {
+ var suggestedCatalogue = Regex.Replace(termCatalogues?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
+
+ // calling findwise endpoint with new search text - catalogues
+ termCatalogues = await this.searchService.GetCatalogueSearchResultAsync(
+ new CatalogueSearchRequestModel
+ {
+ SearchText = suggestedCatalogue,
+ PageIndex = pageIndex - 1,
+ PageSize = itemsOnPage,
+ });
+
+ catalogues.DidYouMeanEnabled = true;
+ catalogues.SuggestedCatalogue = suggestedCatalogue;
+ }
+ }
+
catalogues.TotalCount = termCatalogues.TotalHits;
catalogues.GroupId = Guid.NewGuid();
catalogues.Catalogues = termCatalogues.DocumentModel.Select(t => new DashboardCatalogueViewModel
diff --git a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs
index 4f4e07e62..7272e9a27 100644
--- a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs
+++ b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs
@@ -305,12 +305,13 @@ public async Task Image(string name)
[HttpGet("GetAutoSuggestion")]
public async Task GetAutoSuggestion(string term)
{
- var autoSuggestions = await this.searchService.GetAutoSuggestionList(term);
if (!this.User.Identity.IsAuthenticated)
{
return this.RedirectToAction("AccessDenied", "Home");
}
+ var autoSuggestions = await this.searchService.GetAutoSuggestionList(term);
+
return this.PartialView("_AutoComplete", autoSuggestions);
}
}
diff --git a/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj b/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj
index aff1954b5..f20842a9a 100644
--- a/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj
+++ b/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj
@@ -108,7 +108,7 @@
-
+
diff --git a/LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs b/LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs
index c4b0e6a6c..e17f3c851 100644
--- a/LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs
+++ b/LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs
@@ -83,5 +83,10 @@ public class SearchResultViewModel
/// Gets or sets a value indicating whether Did You Mean Enabled or not.
///
public bool DidYouMeanEnabled { get; set; }
+
+ ///
+ /// Gets or sets Suggested Catalogue name.
+ ///
+ public string SuggestedCatalogue { get; set; }
}
}
diff --git a/LearningHub.Nhs.WebUI/Services/SearchService.cs b/LearningHub.Nhs.WebUI/Services/SearchService.cs
index c8628270f..45b7f4276 100644
--- a/LearningHub.Nhs.WebUI/Services/SearchService.cs
+++ b/LearningHub.Nhs.WebUI/Services/SearchService.cs
@@ -63,6 +63,7 @@ public async Task PerformSearch(IPrincipal user, SearchRe
var selectedSortItem = searchSortItemList.Where(x => x.SearchSortType == (SearchSortTypeEnum)searchSortType).FirstOrDefault();
var groupId = Guid.Parse(searchRequest.GroupId);
bool didYouMeanEnabled = false;
+ var suggestedCatalogue = string.Empty;
var resourceSearchPageSize = this.settings.FindwiseSettings.ResourceSearchPageSize;
var catalogueSearchPageSize = this.settings.FindwiseSettings.CatalogueSearchPageSize;
@@ -133,6 +134,7 @@ public async Task PerformSearch(IPrincipal user, SearchRe
if (catalogueResult?.Spell?.Suggestions?.Count > 0)
{
catalogueSearchRequestModel.SearchText = Regex.Replace(catalogueResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
+ suggestedCatalogue = catalogueSearchRequestModel.SearchText;
// calling findwise endpoint with new search text - catalogues
catalogueResultTask = this.GetCatalogueSearchResultAsync(catalogueSearchRequestModel);
@@ -230,6 +232,7 @@ public async Task PerformSearch(IPrincipal user, SearchRe
TotalItems = catalogueResult?.TotalHits ?? 0,
},
DidYouMeanEnabled = didYouMeanEnabled,
+ SuggestedCatalogue = suggestedCatalogue,
};
return searchResultViewModel;
diff --git a/LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml b/LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml
index b976651b2..af1ecfab4 100644
--- a/LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml
+++ b/LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml
@@ -12,6 +12,7 @@
var hasSearchTerm = queryParams.ContainsKey("term");
var searhTerm = hasSearchTerm ? queryParams["term"].ToString() : null;
string cardStyle = "card-provider-details--blank";
+ var suggestedTerm = Model.DidYouMeanEnabled ? Model.SuggestedCatalogue : searhTerm;
string GetCatalogueUrl(string catalogueUrl, SearchClickPayloadModel list, int catalogueId)
{
@@ -19,7 +20,7 @@
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(list?.SearchSignal?.Query));
string groupId = HttpUtility.UrlEncode(Model.GroupId.ToString());
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&itemIndex={list?.HitNumber}
-&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={searhTerm}&catalogueId={catalogueId}
+&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={suggestedTerm}&catalogueId={catalogueId}
&GroupId={groupId}&searchId={list?.SearchSignal.SearchId}&timeOfSearch={list?.SearchSignal.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(list?.SearchSignal?.UserQuery)}
&query={searchSignalQueryEncoded}&name={list?.DocumentFields?.Name}";
return url;
@@ -42,7 +43,7 @@
}
- @(hasSearchTerm ? $"Search results for {searhTerm}" : "All catalogues")
+ @(hasSearchTerm ? $"Search results for {suggestedTerm}" : "All catalogues")
diff --git a/LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml b/LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml
index b26b4ba70..6c1149b38 100644
--- a/LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml
+++ b/LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml
@@ -8,6 +8,7 @@
var catalogueResult = Model.CatalogueSearchResult;
var pagingModel = Model.CatalogueResultPaging;
var searchString = HttpUtility.UrlEncode(Model.SearchString);
+ var suggestedSearchString = Model.DidYouMeanEnabled ? HttpUtility.UrlEncode(Model.SuggestedCatalogue) : HttpUtility.UrlEncode(Model.SearchString);
string GetCatalogueUrl(string catalogueUrl, int nodePathId, int itemIndex, int catalogueId, SearchClickPayloadModel payload)
{
@@ -17,7 +18,7 @@
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(searchSignal?.Query));
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&nodePathId={nodePathId}&itemIndex={payload?.HitNumber}
-&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={searchString}&catalogueId={catalogueId}
+&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={suggestedSearchString}&catalogueId={catalogueId}
&GroupId={groupId}&searchId={searchSignal?.SearchId}&timeOfSearch={searchSignal?.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(searchSignal?.UserQuery)}
&query={searchSignalQueryEncoded}&name={payload?.DocumentFields?.Name}";
return url;
diff --git a/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml b/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml
index 7ec19feef..a0139e3eb 100644
--- a/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml
+++ b/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml
@@ -25,6 +25,9 @@
xhr.open("GET", '@Url.Action("GetAutoSuggestion", "Search")' + '?term=' + encodeURIComponent(term), true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
+ if (xhr.responseText.includes('