Skip to content

Commit

Permalink
Merge pull request #668 from SkillsFundingAgency/MF-475_fix_provider_…
Browse files Browse the repository at this point in the history
…search_for_first_name_last_search

MF-475 fix provider search for first name last search
  • Loading branch information
dashton82 authored Feb 11, 2020
2 parents 7cf6000 + 265964a commit c59891c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ public void And_Uln_Matches_SearchTerm_Then_Included(
}

[Test, RecursiveMoqAutoData]
public void And_FirstName_And_LastName_Matches_SearchTerm_Then_Included(
string searchTerm,
public void And_FirstName_And_LastName_Matches_SearchTerm_Split_on_The_Space(
string searchTermFirstName,
string searchTermLastName,
List<Apprenticeship> apprenticeships)
{
apprenticeships[0].FirstName = searchTerm;
apprenticeships[1].LastName = searchTerm;
var searchTerm = $"{searchTermFirstName} {searchTermLastName}";

apprenticeships[0].FirstName = searchTermFirstName;
apprenticeships[1].LastName = searchTermLastName;
var filter = new ApprenticeshipSearchFilters{SearchTerm = searchTerm};

var filtered = apprenticeships.AsQueryable().Filter(filter);

filtered.Count().Should().Be(apprenticeships.Count(apprenticeship =>
apprenticeship.FirstName == searchTerm ||
apprenticeship.LastName == searchTerm));
apprenticeship.FirstName == searchTermFirstName ||
apprenticeship.LastName == searchTermLastName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,29 @@ public static IQueryable<Apprenticeship> Filter(this IQueryable<Apprenticeship>
{
var found = new List<long>();

found.AddRange(apprenticeships.Where(app =>
app.FirstName.StartsWith(filters.SearchTerm))
.Select(apprenticeship => apprenticeship.Id));
if (!filters.SearchTerm.Contains(" "))
{
found.AddRange(apprenticeships.Where(app =>
app.FirstName.StartsWith(filters.SearchTerm))
.Select(apprenticeship => apprenticeship.Id));

found.AddRange(apprenticeships.Where(app =>
app.LastName.StartsWith(filters.SearchTerm))
.Select(apprenticeship => apprenticeship.Id));
found.AddRange(apprenticeships.Where(app =>
app.LastName.StartsWith(filters.SearchTerm))
.Select(apprenticeship => apprenticeship.Id));
}
else
{
var firstName = filters.SearchTerm.Substring(0, filters.SearchTerm.IndexOf(' '));
var lastName = filters.SearchTerm.Substring(firstName.Length + 1);

found.AddRange(apprenticeships.Where(app =>
app.FirstName.StartsWith(firstName))
.Select(apprenticeship => apprenticeship.Id));

found.AddRange(apprenticeships.Where(app =>
app.LastName.StartsWith(lastName))
.Select(apprenticeship => apprenticeship.Id));
}

apprenticeships = apprenticeships.Where(apprenticeship =>
found.Contains(apprenticeship.Id));
Expand Down
2 changes: 2 additions & 0 deletions src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ CREATE NONCLUSTERED INDEX [IX_Apprenticeship_IsApprovedStartDate_Filter] ON [dbo
GO
CREATE NONCLUSTERED INDEX [IX_Apprenticeship_IsApprovedEndDate_Filter] ON [dbo].[Apprenticeship] ([IsApproved],[EndDate]) INCLUDE ([CommitmentId]) WITH (ONLINE=ON)
GO
CREATE NONCLUSTERED INDEX [IDX_Apprenticeship_ApprovedNameSearch] ON [dbo].[Apprenticeship] ([IsApproved]) INCLUDE ([CommitmentId],[FirstName],[LastName])
GO
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ GO
CREATE NONCLUSTERED INDEX [IX_ApprenticeshipUpdate_ApprenticeshipId_Status] ON [dbo].[ApprenticeshipUpdate] ([ApprenticeshipId], [Status]) INCLUDE ([Originator]) WITH (ONLINE = ON)
GO

CREATE NONCLUSTERED INDEX [IDX_ApprenticeshipUpdate_StatusSearch] ON [dbo].[ApprenticeshipUpdate] ([Status]) INCLUDE ([ApprenticeshipId])
GO
-- this was recommended by azure (with the old apprenticeshipsummary view)
--CREATE NONCLUSTERED INDEX [nci_wi_ApprenticeshipUpdate_97B6F3CEAF1484B61E5FC09AB1376AFF] ON [dbo].[ApprenticeshipUpdate] ([Status]) INCLUDE ([ApprenticeshipId], [Originator]) WITH (ONLINE = ON)
--GO
2 changes: 2 additions & 0 deletions src/SFA.DAS.Commitments.Database/Tables/DataLockStatus.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ CREATE NONCLUSTERED INDEX [IX_DataLockStatus_ApprenticeshipId2]
ON [dbo].[DataLockStatus] ([ApprenticeshipId], [IsExpired], [IsResolved], [EventStatus])
INCLUDE ([DataLockEventId], [ErrorCode], [TriageStatus])
GO
CREATE NONCLUSTERED INDEX [IDX_DataLockStatus_StatusEventStatusResolvedSearch] ON [dbo].[DataLockStatus] ([Status],[IsResolved],[EventStatus]) INCLUDE ([ApprenticeshipId])
GO

0 comments on commit c59891c

Please sign in to comment.