Skip to content

Commit 87e5700

Browse files
Merge pull request #740 from TechnologyEnhancedLearning/Develop/Fixes/TD-4870-Fixed-Timeout-issue-and-mismatch-in-counts-in-ViewAllCatalogue-page
TD-4870: Fixed Timeout issue and mismatch in counts in view all catalogue page
2 parents 88dac10 + 6cc45f2 commit 87e5700

File tree

24 files changed

+60
-20
lines changed

24 files changed

+60
-20
lines changed

AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
9090
<PackageReference Include="IdentityModel" Version="4.4.0" />
9191
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
92-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
92+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
9393
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
9494
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
9595
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />

LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Net.Http;
7+
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
89
using LearningHub.Nhs.Caching;
910
using LearningHub.Nhs.Models.Catalogue;
@@ -109,6 +110,28 @@ public async Task<IActionResult> Index(int pageIndex = 1, string term = null)
109110
PageSize = itemsOnPage,
110111
});
111112

113+
// Did you mean suggestion when no hits found
114+
if (termCatalogues?.TotalHits == 0 && termCatalogues?.Spell?.Suggestions?.Count > 0)
115+
{
116+
// pass the spell suggestion as new search text - catalogues
117+
if (termCatalogues?.Spell?.Suggestions?.Count > 0)
118+
{
119+
var suggestedCatalogue = Regex.Replace(termCatalogues?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
120+
121+
// calling findwise endpoint with new search text - catalogues
122+
termCatalogues = await this.searchService.GetCatalogueSearchResultAsync(
123+
new CatalogueSearchRequestModel
124+
{
125+
SearchText = suggestedCatalogue,
126+
PageIndex = pageIndex - 1,
127+
PageSize = itemsOnPage,
128+
});
129+
130+
catalogues.DidYouMeanEnabled = true;
131+
catalogues.SuggestedCatalogue = suggestedCatalogue;
132+
}
133+
}
134+
112135
catalogues.TotalCount = termCatalogues.TotalHits;
113136
catalogues.GroupId = Guid.NewGuid();
114137
catalogues.Catalogues = termCatalogues.DocumentModel.Select(t => new DashboardCatalogueViewModel

LearningHub.Nhs.WebUI/Controllers/SearchController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,13 @@ public async Task<IActionResult> Image(string name)
305305
[HttpGet("GetAutoSuggestion")]
306306
public async Task<IActionResult> GetAutoSuggestion(string term)
307307
{
308-
var autoSuggestions = await this.searchService.GetAutoSuggestionList(term);
309308
if (!this.User.Identity.IsAuthenticated)
310309
{
311310
return this.RedirectToAction("AccessDenied", "Home");
312311
}
313312

313+
var autoSuggestions = await this.searchService.GetAutoSuggestionList(term);
314+
314315
return this.PartialView("_AutoComplete", autoSuggestions);
315316
}
316317
}

LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<PackageReference Include="HtmlAgilityPack" Version="1.11.38" />
109109
<PackageReference Include="IdentityModel" Version="4.3.0" />
110110
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
111-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.42" />
111+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.43" />
112112
<PackageReference Include="linqtotwitter" Version="6.9.0" />
113113
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
114114
<PackageReference Include="Microsoft.ApplicationInsights.EventCounterCollector" Version="2.21.0" />

LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,10 @@ public class SearchResultViewModel
8383
/// Gets or sets a value indicating whether Did You Mean Enabled or not.
8484
/// </summary>
8585
public bool DidYouMeanEnabled { get; set; }
86+
87+
/// <summary>
88+
/// Gets or sets Suggested Catalogue name.
89+
/// </summary>
90+
public string SuggestedCatalogue { get; set; }
8691
}
8792
}

LearningHub.Nhs.WebUI/Services/SearchService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
6363
var selectedSortItem = searchSortItemList.Where(x => x.SearchSortType == (SearchSortTypeEnum)searchSortType).FirstOrDefault();
6464
var groupId = Guid.Parse(searchRequest.GroupId);
6565
bool didYouMeanEnabled = false;
66+
var suggestedCatalogue = string.Empty;
6667

6768
var resourceSearchPageSize = this.settings.FindwiseSettings.ResourceSearchPageSize;
6869
var catalogueSearchPageSize = this.settings.FindwiseSettings.CatalogueSearchPageSize;
@@ -133,6 +134,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
133134
if (catalogueResult?.Spell?.Suggestions?.Count > 0)
134135
{
135136
catalogueSearchRequestModel.SearchText = Regex.Replace(catalogueResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
137+
suggestedCatalogue = catalogueSearchRequestModel.SearchText;
136138

137139
// calling findwise endpoint with new search text - catalogues
138140
catalogueResultTask = this.GetCatalogueSearchResultAsync(catalogueSearchRequestModel);
@@ -230,6 +232,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
230232
TotalItems = catalogueResult?.TotalHits ?? 0,
231233
},
232234
DidYouMeanEnabled = didYouMeanEnabled,
235+
SuggestedCatalogue = suggestedCatalogue,
233236
};
234237

235238
return searchResultViewModel;

LearningHub.Nhs.WebUI/Views/Catalogue/Catalogues.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
var hasSearchTerm = queryParams.ContainsKey("term");
1313
var searhTerm = hasSearchTerm ? queryParams["term"].ToString() : null;
1414
string cardStyle = "card-provider-details--blank";
15+
var suggestedTerm = Model.DidYouMeanEnabled ? Model.SuggestedCatalogue : searhTerm;
1516

1617
string GetCatalogueUrl(string catalogueUrl, SearchClickPayloadModel list, int catalogueId)
1718
{
1819
string encodedCatalogueUrl = HttpUtility.UrlEncode("/Catalogue/" + catalogueUrl);
1920
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(list?.SearchSignal?.Query));
2021
string groupId = HttpUtility.UrlEncode(Model.GroupId.ToString());
2122
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&itemIndex={list?.HitNumber}
22-
&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={searhTerm}&catalogueId={catalogueId}
23+
&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={suggestedTerm}&catalogueId={catalogueId}
2324
&GroupId={groupId}&searchId={list?.SearchSignal.SearchId}&timeOfSearch={list?.SearchSignal.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(list?.SearchSignal?.UserQuery)}
2425
&query={searchSignalQueryEncoded}&name={list?.DocumentFields?.Name}";
2526
return url;
@@ -42,7 +43,7 @@
4243
<vc:back-link asp-controller="Home" asp-action="Index" link-text="Back to: Learning Hub" />
4344
}
4445
<h1 class="nhsuk-u-margin-bottom-5">
45-
@(hasSearchTerm ? $"Search results for {searhTerm}" : "All catalogues")
46+
@(hasSearchTerm ? $"Search results for {suggestedTerm}" : "All catalogues")
4647
</h1>
4748

4849
<h2 class="nhsuk-u-margin-bottom-5">

LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
var catalogueResult = Model.CatalogueSearchResult;
99
var pagingModel = Model.CatalogueResultPaging;
1010
var searchString = HttpUtility.UrlEncode(Model.SearchString);
11+
var suggestedSearchString = Model.DidYouMeanEnabled ? HttpUtility.UrlEncode(Model.SuggestedCatalogue) : HttpUtility.UrlEncode(Model.SearchString);
1112

1213
string GetCatalogueUrl(string catalogueUrl, int nodePathId, int itemIndex, int catalogueId, SearchClickPayloadModel payload)
1314
{
@@ -17,7 +18,7 @@
1718
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(searchSignal?.Query));
1819

1920
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&nodePathId={nodePathId}&itemIndex={payload?.HitNumber}
20-
&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={searchString}&catalogueId={catalogueId}
21+
&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={suggestedSearchString}&catalogueId={catalogueId}
2122
&GroupId={groupId}&searchId={searchSignal?.SearchId}&timeOfSearch={searchSignal?.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(searchSignal?.UserQuery)}
2223
&query={searchSignalQueryEncoded}&name={payload?.DocumentFields?.Name}";
2324
return url;

LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
xhr.open("GET", '@Url.Action("GetAutoSuggestion", "Search")' + '?term=' + encodeURIComponent(term), true);
2626
xhr.onload = function () {
2727
if (xhr.status >= 200 && xhr.status < 400) {
28+
if (xhr.responseText.includes('<script>')) {
29+
return;
30+
}
2831
if (xhr.responseText.trim().length > 5) {
2932
suggestionsList.style.display = "block";
3033
suggestionsList.innerHTML = xhr.responseText;

LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
xhr.open("GET", '@Url.Action("GetAutoSuggestion", "Search")' + '?term=' + encodeURIComponent(term), true);
5050
xhr.onload = function () {
5151
if (xhr.status >= 200 && xhr.status < 400) {
52+
if (xhr.responseText.includes('<script>')) {
53+
return;
54+
}
5255
if (xhr.responseText.trim().length > 5) {
5356
suggestionsList.style.display = "block";
5457
suggestionsList.innerHTML = xhr.responseText;

0 commit comments

Comments
 (0)