Skip to content

Commit

Permalink
updated search indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
dzimchuk committed May 11, 2018
1 parent 585e44e commit c53ade0
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 116 deletions.
5 changes: 3 additions & 2 deletions BookFast.Search.Adapter/BookFast.Search.Adapter.csproj
Expand Up @@ -8,11 +8,12 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BookFast.Search.Business\BookFast.Search.Business.csproj" />
<ProjectReference Include="..\BookFast.Search.Contracts\BookFast.Search.Contracts.csproj" />
<ProjectReference Include="..\Common\BookFast.SeedWork\BookFast.SeedWork.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Search" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Search" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.1" />
<PackageReference Include="AutoMapper" Version="6.2.2" />
Expand Down
6 changes: 3 additions & 3 deletions BookFast.Search.Adapter/BookFastIndex.cs
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
Expand Down Expand Up @@ -37,7 +37,7 @@ private Task CreateIndexAsync(string indexName)
var suggester = new Suggester
{
Name = "sg",
SearchMode = SuggesterSearchMode.AnalyzingInfixMatching,
//SearchMode = "analyzingInfixMatching",
SourceFields = new List<string> { "Name", "FacilityName" }
};

Expand All @@ -47,7 +47,7 @@ private Task CreateIndexAsync(string indexName)
Fields = new List<Field>
{
new Field("Id", DataType.String) { IsKey = true },
new Field("FacilityId", DataType.String) { IsFilterable = true },
new Field("FacilityId", DataType.Int32) { IsFilterable = true },
new Field("Name", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true },
new Field("Description", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true },
new Field("FacilityName", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true },
Expand Down
5 changes: 2 additions & 3 deletions BookFast.Search.Adapter/Composition/CompositionModule.cs
@@ -1,10 +1,9 @@
using BookFast.SeedWork;
using BookFast.SeedWork;
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Azure.Search;
using Microsoft.Extensions.Options;
using BookFast.Search.Business.Data;
using BookFast.Search.Adapter.Mappers;
using BookFast.Search.Contracts;

Expand All @@ -19,7 +18,7 @@ public void AddServices(IServiceCollection services, IConfiguration configuratio
services.AddScoped(provider => CreateSearchIndexClient(provider, true));

services.AddScoped<ISearchResultMapper, SearchResultMapper>();
services.AddScoped<ISearchDataSource>(provider => new SearchDataSource(CreateSearchIndexClient(provider, false), provider.GetService<ISearchResultMapper>()));
services.AddScoped<ISearchServiceProxy>(provider => new SearchServiceProxy(CreateSearchIndexClient(provider, false), provider.GetService<ISearchResultMapper>()));

services.AddSingleton<ISearchIndexer, SearchIndexer>();
}
Expand Down
11 changes: 6 additions & 5 deletions BookFast.Search.Adapter/SearchIndexer.cs
@@ -1,8 +1,7 @@
using BookFast.Search.Contracts;
using BookFast.Search.Contracts;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using Microsoft.Spatial;
using System;
using System.Threading.Tasks;

namespace BookFast.Search.Adapter
Expand All @@ -16,9 +15,9 @@ public SearchIndexer(ISearchIndexClient client)
this.client = client;
}

public Task DeleteAccommodationIndexAsync(Guid accommodationId)
public Task DeleteAccommodationIndexAsync(int accommodationId)
{
var action = IndexAction.Delete(new Document { { "Id", accommodationId } });
var action = IndexAction.Delete(new Document { { "Id", accommodationId.ToString() } });
return client.Documents.IndexAsync(new IndexBatch(new[] { action }));
}

Expand All @@ -32,7 +31,7 @@ private static Document CreateDocument(Contracts.Models.Accommodation accommodat
{
return new Document
{
{ "Id", accommodation.Id },
{ "Id", accommodation.Id.ToString() },
{ "FacilityId", accommodation.FacilityId },
{ "Name", accommodation.Name },
{ "Description", accommodation.Description },
Expand All @@ -47,7 +46,9 @@ private static Document CreateDocument(Contracts.Models.Accommodation accommodat
private static GeographyPoint CreateGeographyPoint(Contracts.Models.Location location)
{
if (location != null && location.Latitude != null && location.Longitude != null)
{
return GeographyPoint.Create(location.Latitude.Value, location.Longitude.Value);
}

return null;
}
Expand Down
@@ -1,20 +1,20 @@
using BookFast.Search.Business.Data;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using SearchResult = BookFast.Search.Contracts.Models.SearchResult;
using SuggestResult = BookFast.Search.Contracts.Models.SuggestResult;
using BookFast.Search.Contracts;

namespace BookFast.Search.Adapter
{
internal class SearchDataSource : ISearchDataSource
internal class SearchServiceProxy : ISearchServiceProxy
{
private const int PageSize = 10;
private readonly ISearchIndexClient client;
private readonly ISearchResultMapper mapper;

public SearchDataSource(ISearchIndexClient client, ISearchResultMapper mapper)
public SearchServiceProxy(ISearchIndexClient client, ISearchResultMapper mapper)
{
this.client = client;
this.mapper = mapper;
Expand Down
12 changes: 0 additions & 12 deletions BookFast.Search.Business/BookFast.Search.Business.csproj

This file was deleted.

15 changes: 0 additions & 15 deletions BookFast.Search.Business/Composition/CompositionModule.cs

This file was deleted.

12 changes: 0 additions & 12 deletions BookFast.Search.Business/Data/ISearchDataSource.cs

This file was deleted.

28 changes: 0 additions & 28 deletions BookFast.Search.Business/SearchService.cs

This file was deleted.

@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using BookFast.Search.Contracts.Models;

namespace BookFast.Search.Contracts
{
public interface ISearchService
public interface ISearchServiceProxy
{
Task<IList<SearchResult>> SearchAsync(string searchText, int page);
Task<IList<SuggestResult>> SuggestAsync(string searchText);
Expand Down
Expand Up @@ -15,9 +15,10 @@ public class UpdateAccommodationCommandHandler : IRequestHandler<UpdateAccommoda
private readonly ISearchIndexer searchIndexer;
private readonly IApiClientFactory<IBookFastFacilityAPI> apiClientFactory;

public UpdateAccommodationCommandHandler(ISearchIndexer searchIndexer)
public UpdateAccommodationCommandHandler(ISearchIndexer searchIndexer, IApiClientFactory<IBookFastFacilityAPI> apiClientFactory)
{
this.searchIndexer = searchIndexer;
this.apiClientFactory = apiClientFactory;
}

public async Task Handle(UpdateAccommodationCommand message, CancellationToken cancellationToken)
Expand Down
5 changes: 3 additions & 2 deletions BookFast.Search.Indexer/IndexerService.cs
Expand Up @@ -4,14 +4,15 @@
using System.Threading.Tasks;
using Microsoft.ServiceFabric.Services.Runtime;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;

namespace BookFast.Search.Indexer
{
internal sealed class IndexerService : StatelessService
{
private readonly IHostedService[] hostedServices;
private readonly IEnumerable<IHostedService> hostedServices;

public IndexerService(StatelessServiceContext context, IHostedService[] hostedServices)
public IndexerService(StatelessServiceContext context, IEnumerable<IHostedService> hostedServices)
: base(context)
{
this.hostedServices = hostedServices;
Expand Down
26 changes: 21 additions & 5 deletions BookFast.Search.Indexer/Integration/IntegrationEventMapper.cs
@@ -1,18 +1,34 @@
using BookFast.Search.Indexer.Commands;
using BookFast.ServiceBus;
using MediatR;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BookFast.Search.Indexer.Integration
{
internal class IntegrationEventMapper : IEventMapper
{
public IBaseRequest MapEvent(string eventName, JObject payload)
{
throw new NotImplementedException();
switch (eventName)
{
case "AccommodationCreatedEvent":
case "AccommodationUpdatedEvent":
return MapUpdate(payload);
case "AccommodationDeletedEvent":
return MapRemove(payload);
default:
return null;
}
}

private static UpdateAccommodationCommand MapUpdate(JObject payload)
{
return payload.ToObject<UpdateAccommodationCommand>();
}

private static RemoveAccommodationCommand MapRemove(JObject payload)
{
return new RemoveAccommodationCommand { Id = int.Parse(payload["Id"].ToString()) };
}
}
}
10 changes: 8 additions & 2 deletions BookFast.Search.Indexer/PackageRoot/Config/Settings.xml
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">

<Section Name="Logging">
<Parameter Name="IncludeScopes" Value="" />
<Parameter Name="LogLevel:Default" Value="" />
<Parameter Name="Debug:LogLevel:Default" Value="" />
</Section>

<Section Name="ApplicationInsights">
<Parameter Name="InstrumentationKey" Value="" />
</Section>
Expand All @@ -19,8 +25,8 @@
</Section>

<Section Name="FacilityApi">
<Parameter Name="ServiceUri" Value="fabric:/BookFast/FacilityService" />
<Parameter Name="ServiceApiResource" Value="App ID URI of the API app in Azure AD" />
<Parameter Name="ServiceUri" Value="" />
<Parameter Name="ServiceApiResource" Value="" />
</Section>

</Settings>
8 changes: 8 additions & 0 deletions BookFast.Search.Indexer/Program.cs
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Diagnostics.EventFlow.ServiceFabric;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Services.Runtime;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -71,6 +72,13 @@ private static IndexerService CreateServiceInstance(StatelessServiceContext cont
private static IServiceProvider GetServiceProvider(IConfigurationRoot configuration, StatelessServiceContext context)
{
var services = new ServiceCollection();
services.AddOptions();
services.AddLogging(logging =>
{
logging.AddConfiguration(configuration.GetSection("Logging"));
logging.AddDebug();
});

var modules = new List<ICompositionModule>
{
new Composition.CompositionModule(),
Expand Down
4 changes: 2 additions & 2 deletions BookFast.Search/Controllers/SearchController.cs
Expand Up @@ -10,9 +10,9 @@ namespace BookFast.Search.Controllers
[Route("api/[controller]")]
public class SearchController : Controller
{
private readonly ISearchService service;
private readonly ISearchServiceProxy service;

public SearchController(ISearchService service)
public SearchController(ISearchServiceProxy service)
{
this.service = service;
}
Expand Down
1 change: 0 additions & 1 deletion BookFast.Search/Startup.cs
Expand Up @@ -26,7 +26,6 @@ public void ConfigureServices(IServiceCollection services)
var modules = new List<ICompositionModule>
{
new Composition.CompositionModule(),
new Business.Composition.CompositionModule(),
new Adapter.Composition.CompositionModule()
};

Expand Down
12 changes: 1 addition & 11 deletions BookFast.sln
Expand Up @@ -31,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Swagger", "Common\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Search.Contracts", "BookFast.Search.Contracts\BookFast.Search.Contracts.csproj", "{E22CBBBD-BC13-4BF1-9CB9-5A64A1BE4D56}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Search.Business", "BookFast.Search.Business\BookFast.Search.Business.csproj", "{2FF4F0A1-730C-4D7B-AC93-116782647031}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Search.Adapter", "BookFast.Search.Adapter\BookFast.Search.Adapter.csproj", "{BE437B8D-6468-4197-828A-BE57405F3F87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Search", "BookFast.Search\BookFast.Search.csproj", "{79EDEC05-1B36-4631-8F2A-92F180957469}"
Expand Down Expand Up @@ -77,7 +75,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.ServiceBus", "Comm
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.Security", "Common\BookFast.Security\BookFast.Security.csproj", "{C397B8BA-19A2-4FA7-8FB0-1E210C81B875}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookFast.ReliableEvents", "Common\BookFast.ReliableEvents\BookFast.ReliableEvents.csproj", "{C354EEE2-6202-4994-BF7D-DB2B27DBE6D8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookFast.ReliableEvents", "Common\BookFast.ReliableEvents\BookFast.ReliableEvents.csproj", "{C354EEE2-6202-4994-BF7D-DB2B27DBE6D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -167,14 +165,6 @@ Global
{E22CBBBD-BC13-4BF1-9CB9-5A64A1BE4D56}.Release|Any CPU.Build.0 = Release|Any CPU
{E22CBBBD-BC13-4BF1-9CB9-5A64A1BE4D56}.Release|x64.ActiveCfg = Release|Any CPU
{E22CBBBD-BC13-4BF1-9CB9-5A64A1BE4D56}.Release|x64.Build.0 = Release|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Debug|x64.ActiveCfg = Debug|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Debug|x64.Build.0 = Debug|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Release|Any CPU.Build.0 = Release|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Release|x64.ActiveCfg = Release|Any CPU
{2FF4F0A1-730C-4D7B-AC93-116782647031}.Release|x64.Build.0 = Release|Any CPU
{BE437B8D-6468-4197-828A-BE57405F3F87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE437B8D-6468-4197-828A-BE57405F3F87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE437B8D-6468-4197-828A-BE57405F3F87}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down

0 comments on commit c53ade0

Please sign in to comment.