protected override AddressMatchBuilder?DoMatchInternal(AddressMatchBuilder?results)
        {
            var municipalities = _latestQueries
                                 .GetAllLatestMunicipalities()
                                 .ToList();

            var municipalitiesByName = FilterByName(municipalities, results);

            var municipalitiesByNisCode = FilterByNisCode(municipalities, results);

            results?.AddMunicipalities(municipalitiesByName.Union(municipalitiesByNisCode));

            if (results.Distinct(new MunicipalityNameComparer()).Count() > 1)
            {
                _warnings.AddWarning("9", "Geen overeenkomst tussen 'Niscode' en 'Gemeentenaam'.");
            }

            if (!string.IsNullOrEmpty(results?.Query.PostalCode))
            {
                results
                .AddMunicipalitiesByPostalCode(
                    FilterByPostalCode(municipalities, results),
                    results.Query.PostalCode);
            }

            if (string.IsNullOrEmpty(results?.Query.MunicipalityName) || results.Any())
            {
                return(results);
            }

            var municipalitiesByPostalCode = FilterByPartOfMunicipality(municipalities, results)
                                             .GroupBy(municipalityPostCode => municipalityPostCode.Item1);

            foreach (var municipalitiesGroup in municipalitiesByPostalCode)
            {
                results.AddMunicipalitiesByPostalCode(
                    municipalitiesGroup
                    .Select(municipalityPostCode => municipalityPostCode.Item2),
                    municipalitiesGroup.Key);
            }

            if (results.Any())
            {
                return(results);
            }

            var municipalitiesByFuzzyMatch = municipalities
                                             .Where(municipality =>
                                                    !string.IsNullOrWhiteSpace(municipality.NameDutchSearch) && municipality.NameDutchSearch.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold) ||
                                                    !string.IsNullOrWhiteSpace(municipality.NameFrenchSearch) && municipality.NameFrenchSearch.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold) ||
                                                    !string.IsNullOrWhiteSpace(municipality.NameGermanSearch) && municipality.NameGermanSearch.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold) ||
                                                    !string.IsNullOrWhiteSpace(municipality.NameEnglishSearch) && municipality.NameEnglishSearch.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold));

            results.AddMunicipalities(municipalitiesByFuzzyMatch);

            return(results);
        }
예제 #2
0
        protected override AddressMatchBuilder DoMatchInternal(AddressMatchBuilder results)
        {
            var municipalities = _latestQueries.GetAllLatestMunicipalities().ToList();

            var municipalitiesByName = FilterByName(municipalities, results);

            var municipalitiesByNisCode = FilterByNisCode(municipalities, results);

            results.AddMunicipalities(municipalitiesByName.Union(municipalitiesByNisCode));
            if (results.Count() > 1)
            {
                _warnings.AddWarning("9", "Geen overeenkomst tussen 'Niscode' en 'Gemeentenaam'.");
            }

            if (!string.IsNullOrEmpty(results.Query.PostalCode))
            {
                results.AddMunicipalitiesByPostalCode(FilterByPostalcode(municipalities, results), results.Query.PostalCode);
            }

            if (!string.IsNullOrEmpty(results.Query.MunicipalityName) && !results.Any())
            {
                var municipalitiesByPostalCode = FilterByPartOfMunicipality(municipalities, results)
                                                 .GroupBy(municipalityPostCode => municipalityPostCode.Item1);

                foreach (var municipalitiesGroup in municipalitiesByPostalCode)
                {
                    results.AddMunicipalitiesByPostalCode(municipalitiesGroup.Select(municipalityPostCode => municipalityPostCode.Item2), municipalitiesGroup.Key);
                }

                if (!results.Any())
                {
                    var municipalitiesByFuzzyMatch = municipalities.Where(g => g.DefaultName.Value.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold));
                    results.AddMunicipalities(municipalitiesByFuzzyMatch);
                }
            }

            //_telemetry.TrackGemeenteMatch(results.Query.Gemeentenaam, results.Query.Niscode, results.Query.Postcode, results.Count());

            return(results);
        }