diff --git a/src/AssociationRegistry.Admin.Api/DuplicateDetection/SearchDuplicateVerenigingDetectionService.cs b/src/AssociationRegistry.Admin.Api/DuplicateDetection/SearchDuplicateVerenigingDetectionService.cs index f0da6b05d..3e181fba4 100644 --- a/src/AssociationRegistry.Admin.Api/DuplicateDetection/SearchDuplicateVerenigingDetectionService.cs +++ b/src/AssociationRegistry.Admin.Api/DuplicateDetection/SearchDuplicateVerenigingDetectionService.cs @@ -36,86 +36,14 @@ public async Task> GetDuplicates(Vereni .Should( sh => sh.Bool(sb => sb .Must( - mu => mu - .Match( - m => m - .Field( - f => f - .Naam) - .Query( - naam) - .Analyzer( - DuplicateDetectionDocumentMapping - .DuplicateAnalyzer) - .Fuzziness( - Fuzziness - .Auto)), - mu => mu - .Nested( - n => n - .Path( - p => p - .Locaties) - .Query( - nq - => nq - .Match( - m => - FuzzyMatchOpNaam( - m, - path - : f - => f - .Locaties - .First() - .Gemeente, - string - .Join( - separator - : " ", - gemeentes)) - ) - ) - ) + mu => MatchNaam(mu, naam), + mu => MatchGemeente(mu, gemeentes) ) ), sh => sh.Bool(sb => sb .Must( - mu => mu - .Match( - m => m - .Field( - f => f - .Naam) - .Query( - naam) - .Analyzer( - DuplicateDetectionDocumentMapping - .DuplicateAnalyzer) - .Fuzziness( - Fuzziness - .Auto)), - mu => mu - .Nested( - n => n - .Path( - p => p - .Locaties) - .Query( - nq - => nq - .Terms( - t => t - .Field( - f => f - .Locaties - .First() - .Postcode) - .Terms( - postcodes) - ) - ) - ) + mu => MatchNaam(mu, naam), + mu => MatchPostcode(mu, postcodes) ) ) ) @@ -127,37 +55,77 @@ public async Task> GetDuplicates(Vereni .ToArray(); } - private static Func, QueryContainer> MatchPostcode(string[] postcodes) + private static QueryContainer MatchNaam(QueryContainerDescriptor mu, VerenigingsNaam naam) { - return postalCodesQuery => postalCodesQuery - .Nested(n => n - .Path(p => p.Locaties) - .Query(nq => nq - .Terms(t => t - .Field(f => f.Locaties - .First() - .Postcode) - .Terms(postcodes) - ) - ) + return mu + .Match( + m => m + .Field( + f => f + .Naam) + .Query( + naam) + .Analyzer( + DuplicateDetectionDocumentMapping + .DuplicateAnalyzer) + .Fuzziness( + Fuzziness + .Auto)); + } + + private static QueryContainer MatchGemeente(QueryContainerDescriptor mu, string[] gemeentes) + { + return mu + .Nested( + n => n + .Path( + p => p + .Locaties) + .Query( + nq + => nq + .Match( + m => + FuzzyMatchOpNaam( + m, + path + : f + => f + .Locaties + .First() + .Gemeente, + string + .Join( + separator + : " ", + gemeentes)) + ) + ) ); } - private static Func, QueryContainer> MatchGemeente(string[] gemeentes) + private static QueryContainer MatchPostcode(QueryContainerDescriptor mu, string[] postcodes) { - return gemeentesQuery => gemeentesQuery - .Nested(n => n - .Path(p => p.Locaties) - .Query(nq => nq - .Match(m => - FuzzyMatchOpNaam(m, - path: f => f.Locaties - .First() - .Gemeente, string.Join( - separator: " ", - gemeentes)) - ) - ) + return mu + .Nested( + n => n + .Path( + p => p + .Locaties) + .Query( + nq + => nq + .Terms( + t => t + .Field( + f => f + .Locaties + .First() + .Postcode) + .Terms( + postcodes) + ) + ) ); }