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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
<PackageReference Include="IdentityModel" Version="4.4.0" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
Expand Down
23 changes: 23 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,28 @@ public async Task<IActionResult> 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
Expand Down
3 changes: 2 additions & 1 deletion LearningHub.Nhs.WebUI/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ public async Task<IActionResult> Image(string name)
[HttpGet("GetAutoSuggestion")]
public async Task<IActionResult> 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.38" />
<PackageReference Include="IdentityModel" Version="4.3.0" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="linqtotwitter" Version="6.9.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.ApplicationInsights.EventCounterCollector" Version="2.21.0" />
Expand Down
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 @@ -83,5 +83,10 @@ public class SearchResultViewModel
/// Gets or sets a value indicating whether Did You Mean Enabled or not.
/// </summary>
public bool DidYouMeanEnabled { get; set; }

/// <summary>
/// Gets or sets Suggested Catalogue name.
/// </summary>
public string SuggestedCatalogue { get; set; }
}
}
3 changes: 3 additions & 0 deletions LearningHub.Nhs.WebUI/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task<SearchResultViewModel> 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;
Expand Down Expand Up @@ -133,6 +134,7 @@ public async Task<SearchResultViewModel> 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);
Expand Down Expand Up @@ -230,6 +232,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
TotalItems = catalogueResult?.TotalHits ?? 0,
},
DidYouMeanEnabled = didYouMeanEnabled,
SuggestedCatalogue = suggestedCatalogue,
};

return searchResultViewModel;
Expand Down
5 changes: 3 additions & 2 deletions LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
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)
{
string encodedCatalogueUrl = HttpUtility.UrlEncode("/Catalogue/" + catalogueUrl);
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;
Expand All @@ -42,7 +43,7 @@
<vc:back-link asp-controller="Home" asp-action="Index" link-text="Back to: Learning Hub" />
}
<h1 class="nhsuk-u-margin-bottom-5">
@(hasSearchTerm ? $"Search results for {searhTerm}" : "All catalogues")
@(hasSearchTerm ? $"Search results for {suggestedTerm}" : "All catalogues")
</h1>

<h2 class="nhsuk-u-margin-bottom-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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('<script>')) {
return;
}
if (xhr.responseText.trim().length > 5) {
suggestionsList.style.display = "block";
suggestionsList.innerHTML = xhr.responseText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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('<script>')) {
return;
}
if (xhr.responseText.trim().length > 5) {
suggestionsList.style.display = "block";
suggestionsList.innerHTML = xhr.responseText;
Expand Down
2 changes: 1 addition & 1 deletion WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Azure.Storage.Queues" Version="12.11.0" />
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="EntityFrameworkCore.Testing.Moq" Version="4.0.0" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.4" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.Azure.Management.DataFactory" Version="4.28.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="5.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.9" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="IdentityModel" Version="5.2.0" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.4" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="elfhHub.Nhs.Models" Version="3.0.8" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="FluentValidation" Version="10.3.4" />
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading