Skip to content

Commit

Permalink
feat: or-1976 remove dots and accents for publiek zoek
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Jan 24, 2024
1 parent 4daee6d commit 243b2f2
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private static QueryContainer MatchQueryString<T>(QueryContainerDescriptor<T> m,
return m.QueryString(
qs =>
qs.Query(query)
.Analyzer(VerenigingZoekDocumentMapping.PubliekZoekenAnalyzer)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public static CreateIndexResponse CreateVerenigingIndex(this IndicesNamespace in
.PatternReplace(name: "underscore_replace",
selector: prcf
=> prcf.Pattern("_").Replacement(" ")))
.TokenFilters(AddDutchStopWordsFilter)
.Normalizers(AddVerenigingZoekNormalizer)
.Analyzers(AddVerenigingZoekAnalyzer)
))
.Map<VerenigingZoekDocument>(VerenigingZoekDocumentMapping.Get));

Expand All @@ -44,7 +46,9 @@ public static async Task<CreateIndexResponse> CreateVerenigingIndexAsync(this In
.PatternReplace(name: "underscore_replace",
selector: prcf
=> prcf.Pattern("_").Replacement(" ")))
.TokenFilters(AddDutchStopWordsFilter)
.Normalizers(AddVerenigingZoekNormalizer)
.Analyzers(AddVerenigingZoekAnalyzer)
))
.Map<VerenigingZoekDocument>(VerenigingZoekDocumentMapping.Get));

Expand All @@ -54,11 +58,25 @@ public static async Task<CreateIndexResponse> CreateVerenigingIndexAsync(this In
return createIndexResponse;
}

private static TokenFiltersDescriptor AddDutchStopWordsFilter(TokenFiltersDescriptor tf)
=> tf.Stop(name: "dutch_stop", selector: st => st
.StopWords("_dutch_") // Or provide your custom list
);

private static NormalizersDescriptor AddVerenigingZoekNormalizer(NormalizersDescriptor ad)
=> ad.Custom(VerenigingZoekDocumentMapping.PubliekZoekenAnalyzer,
=> ad.Custom(VerenigingZoekDocumentMapping.PubliekZoekenNormalizer,
selector: ca
=> ca
.CharFilters("underscore_replace", "dot_replace")
.Filters("lowercase", "asciifolding")
);

private static AnalyzersDescriptor AddVerenigingZoekAnalyzer(AnalyzersDescriptor ad)
=> ad.Custom(VerenigingZoekDocumentMapping.PubliekZoekenAnalyzer,
selector: ca
=> ca
.Tokenizer("standard")
.CharFilters("underscore_replace", "dot_replace")
.Filters("lowercase", "asciifolding", "dutch_stop")
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ namespace AssociationRegistry.Public.Schema.Search;

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


public static TypeMappingDescriptor<VerenigingZoekDocument> Get(TypeMappingDescriptor<VerenigingZoekDocument> map)
=> map.Properties(
descriptor => descriptor
.Keyword(
propertyDescriptor => propertyDescriptor
.Name(document => document.VCode))
.Name(document => document.VCode)
.Normalizer(PubliekZoekenNormalizer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Naam)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Roepnaam)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.KorteNaam)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.KorteBeschrijving)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Keyword(
propertyDescriptor => propertyDescriptor
.Name(document => document.Status))
Expand Down Expand Up @@ -80,11 +83,11 @@ public static IPromise<IProperties> Get(PropertiesDescriptor<VerenigingZoekDocum
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Naam)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Adresvoorstelling)
.WithKeyword(PubliekZoekenAnalyzer))
.WithKeyword(PubliekZoekenNormalizer))
.Boolean(
propertyDescriptor => propertyDescriptor
.Name(document => document.IsPrimair)
Expand All @@ -99,7 +102,7 @@ public static IPromise<IProperties> Get(PropertiesDescriptor<VerenigingZoekDocum
.Text(
propertyDescriptor => propertyDescriptor
.Name(document => document.Gemeente)
.WithKeyword(PubliekZoekenAnalyzer));
.WithKeyword(PubliekZoekenNormalizer));
}

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

private static class RelatieMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace AssociationRegistry.Test.Public.Api.When_Searching;

using Fixtures;
using Fixtures.GivenEvents;
using Fixtures.GivenEvents.Scenarios;
using FluentAssertions;
using templates;
using Test.Framework;
using Xunit;
using Xunit.Categories;

[Collection(nameof(PublicApiCollection))]
[Category("PublicApi")]
[IntegrationTest]
public class With_Accents_Not_Matching
{
private readonly PublicApiClient _publicApiClient;
private readonly V020_Vereniging20ForSearchScenario _scenario;
private readonly string _query = "nôôït";

public With_Accents_Not_Matching(GivenEventsFixture fixture)
{
_publicApiClient = fixture.PublicApiClient;
_scenario = fixture.V020Vereniging20ForSearchScenario;
}

[Fact]
public async Task Then_we_get_a_successful_response()
=> (await _publicApiClient.Search(_query)).Should().BeSuccessful();

[Fact]
public async Task? Then_we_retrieve_one_vereniging_matching_the_name_searched()
{
var response = await _publicApiClient.Search(_query);
var content = await response.Content.ReadAsStringAsync();

var goldenMaster =
new ZoekVerenigingenResponseTemplate()
.FromQuery(_query)
.WithVereniging(
v => v
.FromEvent(_scenario.FeitelijkeVerenigingWerdGeregistreerd)
);

content.Should().BeEquivalentJson(goldenMaster);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace AssociationRegistry.Test.Public.Api.When_Searching;

using Fixtures;
using Fixtures.GivenEvents;
using Fixtures.GivenEvents.Scenarios;
using FluentAssertions;
using templates;
using Test.Framework;
using Xunit;
using Xunit.Categories;

[Collection(nameof(PublicApiCollection))]
[Category("PublicApi")]
[IntegrationTest]
public class With_Dot_Not_Matching
{
private readonly PublicApiClient _publicApiClient;
private readonly V019_Vereniging19ForSearchScenario _scenario;
private readonly string _query = "N.A.S.A.";

public With_Dot_Not_Matching(GivenEventsFixture fixture)
{
_publicApiClient = fixture.PublicApiClient;
_scenario = fixture.V019Vereniging19ForSearchScenario;
}

[Fact]
public async Task Then_we_get_a_successful_response()
=> (await _publicApiClient.Search(_query)).Should().BeSuccessful();

[Fact]
public async Task? Then_we_retrieve_one_vereniging_matching_the_name_searched()
{
var response = await _publicApiClient.Search(_query);
var content = await response.Content.ReadAsStringAsync();

var goldenMaster =
new ZoekVerenigingenResponseTemplate()
.FromQuery(_query)
.WithVereniging(
v => v
.FromEvent(_scenario.FeitelijkeVerenigingWerdGeregistreerd)
);

content.Should().BeEquivalentJson(goldenMaster);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace AssociationRegistry.Test.Public.Api.When_Searching;

using Fixtures;
using Fixtures.GivenEvents;
using Fixtures.GivenEvents.Scenarios;
using FluentAssertions;
using templates;
using Test.Framework;
using Xunit;
using Xunit.Categories;

[Collection(nameof(PublicApiCollection))]
[Category("PublicApi")]
[IntegrationTest]
public class With_Functiewoorden
{
private readonly PublicApiClient _publicApiClient;
private readonly V019_Vereniging19ForSearchScenario _scenario;
private readonly string _query = "de het Auto";

public With_Functiewoorden(GivenEventsFixture fixture)
{
_publicApiClient = fixture.PublicApiClient;
_scenario = fixture.V019Vereniging19ForSearchScenario;
}

[Fact]
public async Task Then_we_get_a_successful_response()
=> (await _publicApiClient.Search(_query)).Should().BeSuccessful();

[Fact]
public async Task? Then_we_retrieve_one_vereniging_matching_the_name_searched()
{
var response = await _publicApiClient.Search(_query);
var content = await response.Content.ReadAsStringAsync();

var goldenMaster =
new ZoekVerenigingenResponseTemplate()
.FromQuery(_query)
.WithVereniging(
v => v
.FromEvent(_scenario.FeitelijkeVerenigingWerdGeregistreerd)
);

content.Should().BeEquivalentJson(goldenMaster);
}
}

0 comments on commit 243b2f2

Please sign in to comment.