Skip to content

Commit

Permalink
feat: or-1976 voeg normalizer toe aan Ãpubliek zoeken
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Jan 22, 2024
1 parent abda924 commit 0868a9c
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/AssociationRegistry.Public.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static async Task Main(string[] args)
.UseEndpoints(routeBuilder => routeBuilder.MapControllers());

ConfigureLifetimeHooks(app);
await app.ConfigureElasticSearch();
//await app.ConfigureElasticSearch();

await app.RunAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,59 @@

public static class ElasticClientExtensions
{
public static async Task<CreateIndexResponse> CreateVerenigingIndex(this IndicesNamespace indicesNamespace, IndexName index)
=> await indicesNamespace.CreateAsync(
public static CreateIndexResponse CreateVerenigingIndex(this IndicesNamespace indicesNamespace, IndexName index)
{
var createIndexResponse = indicesNamespace.Create(
index,
selector: descriptor =>
descriptor.Map<VerenigingZoekDocument>(VerenigingZoekDocumentMapping.Get));
descriptor
.Settings(s => s
.Analysis(a => a
.CharFilters(cf => cf.PatternReplace(name: "dot_replace",
selector: prcf
=> prcf.Pattern("\\.").Replacement(""))
.PatternReplace(name: "underscore_replace",
selector: prcf
=> prcf.Pattern("_").Replacement(" ")))
.Normalizers(AddVerenigingZoekNormalizer)
))
.Map<VerenigingZoekDocument>(VerenigingZoekDocumentMapping.Get));

if (!createIndexResponse.IsValid)
throw createIndexResponse.OriginalException;

return createIndexResponse;
}

public static async Task<CreateIndexResponse> CreateVerenigingIndexAsync(this IndicesNamespace indicesNamespace, IndexName index)
{
var createIndexResponse = await indicesNamespace.CreateAsync(
index,
selector: descriptor =>
descriptor
.Settings(s => s
.Analysis(a => a
.CharFilters(cf => cf.PatternReplace(name: "dot_replace",
selector: prcf
=> prcf.Pattern("\\.").Replacement(""))
.PatternReplace(name: "underscore_replace",
selector: prcf
=> prcf.Pattern("_").Replacement(" ")))
.Normalizers(AddVerenigingZoekNormalizer)
))
.Map<VerenigingZoekDocument>(VerenigingZoekDocumentMapping.Get));

if (!createIndexResponse.IsValid)
throw createIndexResponse.OriginalException;

return createIndexResponse;
}

private static NormalizersDescriptor AddVerenigingZoekNormalizer(NormalizersDescriptor ad)
=> ad.Custom(VerenigingZoekDocumentMapping.PubliekZoekenAnalyzer,
selector: ca
=> ca
.CharFilters("underscore_replace", "dot_replace")
.Filters("lowercase", "asciifolding")
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static async Task EnsureIndexExists(IElasticClient elasticClient, string
{
if (!(await elasticClient.Indices.ExistsAsync(verenigingenIndexName)).Exists)
{
var response = await elasticClient.Indices.CreateVerenigingIndex(verenigingenIndexName);
var response = elasticClient.Indices.CreateVerenigingIndex(verenigingenIndexName);

if (!response.IsValid)
throw response.OriginalException;
Expand Down
2 changes: 1 addition & 1 deletion src/AssociationRegistry.Public.ProjectionHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static async Task Main(string[] args)
await projectionDaemon.StopShard($"{ProjectionNames.VerenigingZoeken}:All");

await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: cancellationToken);

Check warning on line 107 in src/AssociationRegistry.Public.ProjectionHost/Program.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Acm.Api)

Dereference of a possibly null reference.
await elasticClient.Indices.CreateVerenigingIndex(options.Indices.Verenigingen);
await elasticClient.Indices.CreateVerenigingIndexAsync(options.Indices.Verenigingen);

await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, cancellationToken);
logger.LogInformation("Rebuild complete");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ namespace AssociationRegistry.Public.Schema.Search;

public static class PropertyDescriptorExtensions
{
public static TDescriptor WithKeyword<TDescriptor, TInterface, T>(this CorePropertyDescriptorBase<TDescriptor, TInterface, T> source)
public static TDescriptor WithKeyword<TDescriptor, TInterface, T>(
this CorePropertyDescriptorBase<TDescriptor, TInterface, T> source,
string? normalizer = null)
where TDescriptor : CorePropertyDescriptorBase<TDescriptor, TInterface, T>, TInterface
where TInterface : class, ICoreProperty
where T : class
=> source.Fields(x => x.Keyword(y => y.Name("keyword")));
{
return source.Fields(x =>
x.Keyword(
y =>
normalizer is null
? y.Name("keyword")
: y.Name("keyword").Normalizer(normalizer)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace AssociationRegistry.Public.Schema.Search;

public static class VerenigingZoekDocumentMapping
{
public const string PubliekZoekenAnalyzer = "publiek_zoeken_analyzer";

public static TypeMappingDescriptor<VerenigingZoekDocument> Get(TypeMappingDescriptor<VerenigingZoekDocument> map)
=> map.Properties(
descriptor => descriptor
Expand All @@ -13,15 +15,15 @@ public static TypeMappingDescriptor<VerenigingZoekDocument> Get(TypeMappingDescr
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Naam)
.WithKeyword())
.WithKeyword(PubliekZoekenAnalyzer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Roepnaam)
.WithKeyword())
.WithKeyword(PubliekZoekenAnalyzer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.KorteNaam)
.WithKeyword())
.WithKeyword(PubliekZoekenAnalyzer))
.Keyword(
propertyDescriptor => propertyDescriptor
.Name(document => document.Status))
Expand Down Expand Up @@ -74,11 +76,11 @@ public static IPromise<IProperties> Get(PropertiesDescriptor<VerenigingZoekDocum
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Naam)
.WithKeyword())
.WithKeyword(PubliekZoekenAnalyzer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Adresvoorstelling)
.WithKeyword())
.WithKeyword(PubliekZoekenAnalyzer))
.Boolean(
propertyDescriptor => propertyDescriptor
.Name(document => document.IsPrimair)
Expand All @@ -93,7 +95,7 @@ public static IPromise<IProperties> Get(PropertiesDescriptor<VerenigingZoekDocum
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Gemeente)
.WithKeyword());
.WithKeyword(PubliekZoekenAnalyzer));
}

private static class HoofdactiviteitMapping
Expand Down Expand Up @@ -148,7 +150,7 @@ public static IPromise<IProperties> Get(PropertiesDescriptor<VerenigingZoekDocum
.Text(
propertiesDescriptor => propertiesDescriptor
.Name(document => document.Waarde)
.WithKeyword());
.WithKeyword(PubliekZoekenAnalyzer));
}

private static class RelatieMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected AdminApiFixture()
.GetAwaiter().GetResult();

DropDatabase();

EnsureDbExists(GetConfiguration());

OaktonEnvironment.AutoStartHost = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public readonly V017_VerenigingMetRechtspersoonlijkheidWerdGeregistreerd_With_Wi
V017VerenigingMetRechtspersoonlijkheidWerdGeregistreerdWithWijzigMaatschappelijkeZetelScenario = new();

public readonly V018_FeitelijkeVerenigingWerdVerwijderdScenario V018_FeitelijkeVerenigingWerdVerwijderdScenario = new();
public readonly V019_Vereniging19ForSearchScenario V019Vereniging19ForSearchScenario = new();
public readonly V020_Vereniging20ForSearchScenario V020Vereniging20ForSearchScenario = new();

private IEnumerable<IScenario> Scenarios
=> new IScenario[]
Expand All @@ -57,6 +59,8 @@ private IEnumerable<IScenario> Scenarios
V016VerenigingWerdGestopt,
V017VerenigingMetRechtspersoonlijkheidWerdGeregistreerdWithWijzigMaatschappelijkeZetelScenario,
V018_FeitelijkeVerenigingWerdVerwijderdScenario,
V019Vereniging19ForSearchScenario,
V020Vereniging20ForSearchScenario,
};

public override async Task InitializeAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static void ConfigureElasticClient(IElasticClient client, string verenig
if (client.Indices.Exists(verenigingenIndexName).Exists)
client.Indices.Delete(verenigingenIndexName);

client.Indices.CreateVerenigingIndex(verenigingenIndexName);
AssociationRegistry.Public.ProjectionHost.Infrastructure.Extensions.ElasticClientExtensions.CreateVerenigingIndex(client.Indices, verenigingenIndexName);

client.Indices.Refresh(Indices.All);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace AssociationRegistry.Test.Public.Api.Fixtures.GivenEvents.Scenarios;

using AssociationRegistry.Framework;
using Events;
using NodaTime;
using Vereniging;

public class V019_Vereniging19ForSearchScenario : IScenario
{
public readonly FeitelijkeVerenigingWerdGeregistreerd FeitelijkeVerenigingWerdGeregistreerd = new(
VCode: "V0001019",
Naam: "Nieuwe Auto's die Starten Afligem",
KorteNaam: "NASA",
KorteBeschrijving: "Wij verzamelen nieuwe en oude autos.",
DateOnly.FromDateTime(new DateTime(year: 2024, month: 01, day: 22)),
new Registratiedata.Doelgroep(Minimumleeftijd: 18, Maximumleeftijd: 99),
IsUitgeschrevenUitPubliekeDatastroom: false,
new[]
{
new Registratiedata.Contactgegeven(
ContactgegevenId: 1,
Contactgegeventype.Website,
Waarde: "example.org/nasafligem",
Beschrijving: "Algemeen",
IsPrimair: true),
},
new[]
{
new Registratiedata.Locatie(
LocatieId: 1,
Locatietype: "Correspondentie",
IsPrimair: true,
Naam: "Correspondentie",
new Registratiedata.Adres(
Straatnaam: "wasstraat",
Huisnummer: "5",
Busnummer: "",
Postcode: "1790",
Gemeente: "Affligem",
Land: "België"),
new Registratiedata.AdresId(
Adresbron.AR,
Bronwaarde: "https://data.vlaanderen.be/id/adres/0")
),
},
new[]
{
new Registratiedata.Vertegenwoordiger(
VertegenwoordigerId: 1,
Insz: "01234567890",
IsPrimair: true,
Roepnaam: "engine",
Rol: "Leader",
Voornaam: "Put",
Achternaam: "Put",
Email: "putput@broembroem.com",
Telefoon: "",
Mobiel: "",
SocialMedia: ""),
},
new Registratiedata.HoofdactiviteitVerenigingsloket[]
{
new(Code: "BLA", Naam: "Buitengewoon Leuke Afkortingen"),
});

public VCode VCode
=> VCode.Create(FeitelijkeVerenigingWerdGeregistreerd.VCode);

public IEvent[] GetEvents()
{
return new IEvent[]
{
FeitelijkeVerenigingWerdGeregistreerd,
};
}

public CommandMetadata GetCommandMetadata()
=> new(Initiator: "OVO000001", new Instant(), Guid.NewGuid());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace AssociationRegistry.Test.Public.Api.Fixtures.GivenEvents.Scenarios;

using AssociationRegistry.Framework;
using Events;
using NodaTime;
using Vereniging;

public class V020_Vereniging20ForSearchScenario : IScenario
{
public readonly FeitelijkeVerenigingWerdGeregistreerd FeitelijkeVerenigingWerdGeregistreerd = new(
VCode: "V0001020",
Naam: "nooit oma's zonder wafels",
KorteNaam: "nozw",
KorteBeschrijving: "Oma's die houden van bakken",
DateOnly.FromDateTime(new DateTime(year: 2024, month: 01, day: 22)),
new Registratiedata.Doelgroep(Minimumleeftijd: 60, Maximumleeftijd: 99),
IsUitgeschrevenUitPubliekeDatastroom: false,
new[]
{
new Registratiedata.Contactgegeven(
ContactgegevenId: 1,
Contactgegeventype.Telefoon,
Waarde: "0000112233",
Beschrijving: "Algemeen",
IsPrimair: true),
},
new[]
{
new Registratiedata.Locatie(
LocatieId: 1,
Locatietype: "Correspondentie",
IsPrimair: true,
Naam: "Correspondentie",
new Registratiedata.Adres(
Straatnaam: "bakkershof",
Huisnummer: "60",
Busnummer: "B",
Postcode: "1840",
Gemeente: "Londerzeel",
Land: "België"),
new Registratiedata.AdresId(
Adresbron.AR,
Bronwaarde: "https://data.vlaanderen.be/id/adres/0")
),
},
new[]
{
new Registratiedata.Vertegenwoordiger(
VertegenwoordigerId: 1,
Insz: "01234567890",
IsPrimair: true,
Roepnaam: "bakkerijhoofd",
Rol: "Bakker",
Voornaam: "Beau",
Achternaam: "Ter Ham",
Email: "",
Telefoon: "",
Mobiel: "",
SocialMedia: ""),
},
new Registratiedata.HoofdactiviteitVerenigingsloket[]
{
new(Code: "BLA", Naam: "Buitengewoon Leuke Afkortingen"),
});

public VCode VCode
=> VCode.Create(FeitelijkeVerenigingWerdGeregistreerd.VCode);

public IEvent[] GetEvents()
{
return new IEvent[]
{
FeitelijkeVerenigingWerdGeregistreerd,
};
}

public CommandMetadata GetCommandMetadata()
=> new(Initiator: "OVO000001", new Instant(), Guid.NewGuid());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AssociationRegistry.Test.Public.Api.Framework;

public class CaseInsensitiveComparer : IComparer<string>
{
public int Compare(string? x, string? y)
=> string.Compare(x, y, StringComparison.InvariantCultureIgnoreCase);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Given_Sort_By_SingleField(GivenEventsFixture fixture, ITestOutputHelper h
.ToList();

names.Should().NotBeEmpty();
names.Should().BeInAscendingOrder(new CaseSensitiveComparer());
names.Should().BeInAscendingOrder(new CaseInsensitiveComparer());
names.ForEach(_outputHelper.WriteLine);
}

Expand All @@ -60,7 +60,7 @@ public Given_Sort_By_SingleField(GivenEventsFixture fixture, ITestOutputHelper h
.ToList();

names.Should().NotBeEmpty();
names.Should().BeInDescendingOrder(new CaseSensitiveComparer());
names.Should().BeInDescendingOrder(new CaseInsensitiveComparer());
names.ForEach(_outputHelper.WriteLine);
}
}
Loading

0 comments on commit 0868a9c

Please sign in to comment.