Skip to content

Commit

Permalink
Added common cog search package (which now resides under GitHub) (#32)
Browse files Browse the repository at this point in the history
* Removed component lib cog search package in favour of common cog search package (which now resides under GitHub)

* Adjusted search by keyword namespaces

---------

Co-authored-by: Spencer O'HEGARTY <[email protected]>
  • Loading branch information
spanersoraferty and spencerohegartyDfE authored Aug 1, 2024
1 parent 1e0e6dc commit d2b40b5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions Dfe.Data.SearchPrototype.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Data.SearchPrototype.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{0D4ACC06-9FA9-422A-8F92-92B565879E16}"
ProjectSection(SolutionItems) = preProject
NuGet\DfE.Data.ComponentLibrary.CrossCuttingConcerns.Json.2.0.37-beta-ci-20240610-104522.nupkg = NuGet\DfE.Data.ComponentLibrary.CrossCuttingConcerns.Json.2.0.37-beta-ci-20240610-104522.nupkg
NuGet\DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch.2.0.37-beta-ci-20240610-104522.nupkg = NuGet\DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch.2.0.37-beta-ci-20240610-104522.nupkg
NuGet\Dfe.Data.Common.Infrastructure.CognitiveSearch.1.0.0.nupkg = NuGet\Dfe.Data.Common.Infrastructure.CognitiveSearch.1.0.0.nupkg
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Data.SearchPrototype.Infrastructure", "Dfe.Data.SearchPrototype\Infrastructure\Dfe.Data.SearchPrototype.Infrastructure.csproj", "{95EDB119-5238-451B-944A-84A1F8891171}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using Dfe.Data.Common.Infrastructure.CognitiveSearch.SearchByKeyword;
using Dfe.Data.SearchPrototype.Common.Mappers;
using Dfe.Data.SearchPrototype.Infrastructure.Options;
using Dfe.Data.SearchPrototype.SearchForEstablishments;
using DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch.Search;

namespace Dfe.Data.SearchPrototype.Infrastructure;

Expand All @@ -14,16 +14,16 @@ namespace Dfe.Data.SearchPrototype.Infrastructure;
/// </summary>
public sealed class CognitiveSearchServiceAdapter<TSearchResult> : ISearchServiceAdapter where TSearchResult : class
{
private readonly ISearchService _cognitiveSearchService;
private readonly ISearchByKeywordService _searchByKeywordService;
private readonly ISearchOptionsFactory _searchOptionsFactory;
private readonly IMapper<Response<SearchResults<TSearchResult>>, EstablishmentResults> _searchResponseMapper;

/// <summary>
/// The following dependencies include the core cognitive search service definition,
/// the complete implementation of which is defined in the IOC container.
/// </summary>
/// <param name="cognitiveSearchService">
/// Cognitive search service definition injected via IOC container.
/// <param name="searchByKeywordService">
/// Cognitive search (search by keyword) service definition injected via IOC container.
/// </param>
/// <param name="searchOptionsFactory">
/// Factory class definition for prescribing the requested search options (by collection context).
Expand All @@ -32,12 +32,12 @@ public sealed class CognitiveSearchServiceAdapter<TSearchResult> : ISearchServic
/// Maps the raw azure search response to the required "T:Dfe.Data.SearchPrototype.Search.Domain.AgregateRoot.Establishments"
/// </param>
public CognitiveSearchServiceAdapter(
ISearchService cognitiveSearchService,
ISearchByKeywordService searchByKeywordService,
ISearchOptionsFactory searchOptionsFactory,
IMapper<Response<SearchResults<TSearchResult>>, EstablishmentResults> searchResponseMapper)
{
_searchOptionsFactory = searchOptionsFactory;
_cognitiveSearchService = cognitiveSearchService;
_searchByKeywordService = searchByKeywordService;
_searchResponseMapper = searchResponseMapper;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task<EstablishmentResults> SearchAsync(SearchContext searchContext)
$"Search options cannot be derived for {searchContext.TargetCollection}.");

Response<SearchResults<TSearchResult>> searchResults =
await _cognitiveSearchService.SearchAsync<TSearchResult>(
await _searchByKeywordService.SearchAsync<TSearchResult>(
searchContext.SearchKeyword,
searchContext.TargetCollection,
searchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch" Version="2.0.37-beta-CI-20240610-104522" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Azure.Search.Documents" Version="11.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Dfe.Data.Common.Infrastructure.CognitiveSearch" Version="1.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Azure;
using Azure.Search.Documents.Models;
using Dfe.Data.Common.Infrastructure.CognitiveSearch.SearchByKeyword;
using Dfe.Data.SearchPrototype.Common.Mappers;
using Dfe.Data.SearchPrototype.Infrastructure.Options;
using Dfe.Data.SearchPrototype.Infrastructure.Tests.TestDoubles;
using Dfe.Data.SearchPrototype.SearchForEstablishments;
using DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch.Search;
using FluentAssertions;
using Moq;
using Xunit;
Expand All @@ -14,11 +14,11 @@ namespace Dfe.Data.SearchPrototype.Infrastructure.Tests;
public sealed class CognitiveSearchServiceAdapterTests
{
private static CognitiveSearchServiceAdapter<Establishment> CreateServiceAdapterWith(
ISearchService cognitiveSearchService,
ISearchByKeywordService searchByKeywordService,
ISearchOptionsFactory searchOptionsFactory,
IMapper<Response<SearchResults<Establishment>>, EstablishmentResults> searchResponseMapper
) =>
new(cognitiveSearchService, searchOptionsFactory, searchResponseMapper);
new(searchByKeywordService, searchOptionsFactory, searchResponseMapper);

[Fact]
public async Task Search_With_Valid_SearchContext_Returns_Configured_Results()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using DfE.Data.ComponentLibrary.Infrastructure.CognitiveSearch.Search;
using Dfe.Data.Common.Infrastructure.CognitiveSearch.SearchByKeyword;
using Moq;
using System.Linq.Expressions;

namespace Dfe.Data.SearchPrototype.Infrastructure.Tests.TestDoubles;

internal static class SearchServiceTestDouble
{
public static ISearchService DefaultMock() => Mock.Of<ISearchService>();
public static Expression<Func<ISearchService, Task<Response<SearchResults<Establishment>>>>> SearchRequest(string keyword, string collection) =>
public static ISearchByKeywordService DefaultMock() => Mock.Of<ISearchByKeywordService>();
public static Expression<Func<ISearchByKeywordService, Task<Response<SearchResults<Establishment>>>>> SearchRequest(string keyword, string collection) =>
searchService => searchService.SearchAsync<Establishment>(keyword, collection, It.IsAny<SearchOptions>());

public static ISearchService MockFor(Task<Response<SearchResults<Establishment>>> searchResult, string keyword, string collection)
public static ISearchByKeywordService MockFor(Task<Response<SearchResults<Establishment>>> searchResult, string keyword, string collection)
{
var searchServiceMock = new Mock<ISearchService>();
var searchServiceMock = new Mock<ISearchByKeywordService>();

searchServiceMock.Setup(SearchRequest(keyword, collection))
.Returns(searchResult);

return searchServiceMock.Object;
}

public static ISearchService MockSearchService(string keyword, string collection)
public static ISearchByKeywordService MockSearchService(string keyword, string collection)
{
var responseMock = new Mock<Response>();

Expand All @@ -36,7 +36,7 @@ public static ISearchService MockSearchService(string keyword, string collection
return MockFor(validServiceResponseFake, keyword, collection);
}

public static ISearchService MockForDefaultResult()
public static ISearchByKeywordService MockForDefaultResult()
{
var validServiceResponseFake =
Task.FromResult<Response<SearchResults<Establishment>>>(default!);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d2b40b5

Please sign in to comment.