This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from SkillsFundingAgency/FC-544-Add_Missing_p…
…roperties_to_provider_search_result Fc 544 adds provider name search endpoint
- Loading branch information
Showing
19 changed files
with
403 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/SFA.DAS.Apprenticeships.Api.Types/V3/ProviderSearchResults.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SFA.DAS.Apprenticeships.Api.Types.V3 | ||
{ | ||
public sealed class ProviderSearchResults : PagedResults<ProviderSearchResultItem> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Sfa.Das.ApprenticeshipInfoService.Core/Helpers/QueryHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Sfa.Das.ApprenticeshipInfoService.Core.Helpers | ||
{ | ||
public static class QueryHelper | ||
{ | ||
public static string FormatQuery(string query, bool toLower = true) | ||
{ | ||
return string.IsNullOrWhiteSpace(query) ? "*" : ReplaceUnacceptableCharacters(query, toLower); | ||
} | ||
|
||
public static string FormatQueryReturningEmptyStringIfEmptyOrNull(string query, bool toLower = true) | ||
{ | ||
return string.IsNullOrEmpty(query) ? string.Empty : ReplaceUnacceptableCharacters(query, toLower); | ||
} | ||
|
||
private static string ReplaceUnacceptableCharacters(string query, bool toLower) | ||
{ | ||
var queryformatted = Regex.Replace(query, @"[+\-&|!(){}\[\]^""~?:\\/]", @" "); | ||
|
||
return toLower ? queryformatted.ToLowerInvariant() : queryformatted; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Sfa.Das.ApprenticeshipInfoService.Core/Models/ProviderNameSearchResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Sfa.Das.ApprenticeshipInfoService.Core.Models | ||
{ | ||
public class ProviderNameSearchResult | ||
{ | ||
public long UkPrn { get; set; } | ||
public string ProviderName { get; set; } | ||
public List<string> Aliases { get; set; } | ||
public bool IsEmployerProvider { get; set; } | ||
|
||
public bool IsHigherEducationInstitute { get; set; } | ||
public bool HasNonLevyContract { get; set; } | ||
|
||
public bool IsLevyPayerOnly { get; set; } | ||
|
||
public bool CurrentlyNotStartingNewApprentices { get; set; } | ||
public bool NationalProvider { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...fa.Das.ApprenticeshipInfoService.Core/Models/Responses/ProviderNameSearchResponseCodes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Sfa.Das.ApprenticeshipInfoService.Core.Models.Responses | ||
{ | ||
public enum ProviderNameSearchResponseCodes | ||
{ | ||
Success, | ||
SearchFailed, | ||
NoSearchResultsFound, | ||
SearchTermTooShort | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Sfa.Das.ApprenticeshipInfoService.Core/Services/IProviderNameSearchServiceV3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using SFA.DAS.Apprenticeships.Api.Types.V3; | ||
|
||
namespace Sfa.Das.ApprenticeshipInfoService.Core.Services | ||
{ | ||
public interface IProviderNameSearchServiceV3 | ||
{ | ||
Task<ProviderSearchResults> SearchProviderNameAndAliases(string searchTerm, int page, int take); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ceshipInfoService.Infrastructure/Elasticsearch/Querys/IProviderNameSearchProviderQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Nest; | ||
using Sfa.Das.ApprenticeshipInfoService.Core.Models; | ||
|
||
namespace Sfa.Das.ApprenticeshipInfoService.Infrastructure.Elasticsearch.Querys | ||
{ | ||
public interface IProviderNameSearchProviderQuery | ||
{ | ||
ISearchResponse<ProviderNameSearchResult> GetResults(string term, int take, int skip); | ||
long GetTotalMatches(string term); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...iceshipInfoService.Infrastructure/Elasticsearch/Querys/ProviderNameSearchProviderQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using Nest; | ||
using Sfa.Das.ApprenticeshipInfoService.Core.Configuration; | ||
using Sfa.Das.ApprenticeshipInfoService.Core.Models; | ||
|
||
namespace Sfa.Das.ApprenticeshipInfoService.Infrastructure.Elasticsearch.Querys | ||
{ | ||
public class ProviderNameSearchProviderQuery : IProviderNameSearchProviderQuery | ||
{ | ||
private readonly IElasticsearchCustomClient _elasticsearchCustomClient; | ||
private readonly IConfigurationSettings _applicationSettings; | ||
|
||
public ProviderNameSearchProviderQuery(IElasticsearchCustomClient elasticsearchCustomClient, IConfigurationSettings applicationSettings) | ||
{ | ||
_elasticsearchCustomClient = elasticsearchCustomClient; | ||
_applicationSettings = applicationSettings; | ||
} | ||
|
||
public ISearchResponse<ProviderNameSearchResult> GetResults(string term, int take, int skip) | ||
{ | ||
return _elasticsearchCustomClient.Search<ProviderNameSearchResult>(s => s | ||
.Index(_applicationSettings.ProviderIndexAlias) | ||
.Type("providerapidocument") | ||
.Skip(skip) | ||
.Take(take) | ||
.Query(q => q | ||
.Bool(b => b | ||
.Filter(IsNotEmployerProvider()) | ||
.Must(mu => mu | ||
.QueryString(qs => qs | ||
.Fields(fs => fs | ||
.Field(f => f.ProviderName) | ||
.Field(f => f.Aliases)) | ||
.Query(term))) | ||
))); | ||
} | ||
|
||
public long GetTotalMatches(string term) | ||
{ | ||
var initialDetails = _elasticsearchCustomClient.Search<ProviderNameSearchResult>(s => s | ||
.Index(_applicationSettings.ProviderIndexAlias) | ||
.Type("providerapidocument") | ||
.Query(q => q | ||
.Bool(b => b | ||
.Filter(IsNotEmployerProvider()) | ||
.Must(mu => mu | ||
.QueryString(qs => qs | ||
.Fields(fs => fs | ||
.Field(f => f.ProviderName) | ||
.Field(f => f.Aliases)) | ||
.Query(term))) | ||
))); | ||
|
||
return initialDetails.HitsMetaData.Total; | ||
} | ||
|
||
private static Func<QueryContainerDescriptor<ProviderNameSearchResult>, QueryContainer> IsNotEmployerProvider() | ||
{ | ||
return f => f | ||
.Term(t => t | ||
.Field(fi => fi.IsEmployerProvider).Value(false)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.