diff --git a/FuzzySearchNet/FuzzySearchNet.csproj b/FuzzySearchNet/FuzzySearchNet.csproj index 19b68b1..3ffc1bc 100644 --- a/FuzzySearchNet/FuzzySearchNet.csproj +++ b/FuzzySearchNet/FuzzySearchNet.csproj @@ -13,7 +13,7 @@ FuzzySearch.Net - 0.3.2 + 0.3.3 FuzzySearch.Net Verner Fortelius Fuzzy search library for finding strings in strings. Inspired by and attempts to be somewhat compatible with fuzzysearch for python https://github.com/taleinat/fuzzysearch diff --git a/FuzzySearchNet/src/FuzzySearchOptions.cs b/FuzzySearchNet/src/FuzzySearchOptions.cs index cebeead..8a8aab9 100644 --- a/FuzzySearchNet/src/FuzzySearchOptions.cs +++ b/FuzzySearchNet/src/FuzzySearchOptions.cs @@ -6,9 +6,9 @@ public class FuzzySearchOptions { public int MaxTotalDistance { get; private set; } - public int? MaxSubstitutions { get; private set; } - public int? MaxDeletions { get; private set; } - public int? MaxInsertions { get; private set; } + public int MaxSubstitutions { get; private set; } + public int MaxDeletions { get; private set; } + public int MaxInsertions { get; private set; } /// /// Specify total maximum distance @@ -16,6 +16,9 @@ public class FuzzySearchOptions public FuzzySearchOptions(int maxTotalDistance) { MaxTotalDistance = maxTotalDistance; + MaxSubstitutions = maxTotalDistance; + MaxDeletions = maxTotalDistance; + MaxInsertions = maxTotalDistance; } /// @@ -23,9 +26,9 @@ public FuzzySearchOptions(int maxTotalDistance) /// public FuzzySearchOptions(int maxTotalDistance, int? maxSubstitutions = null, int? maxDeletions = null, int? maxInsertions = null) : this(maxTotalDistance) { - MaxSubstitutions = maxSubstitutions; - MaxDeletions = maxDeletions; - MaxInsertions = maxInsertions; + MaxSubstitutions = maxSubstitutions ?? maxTotalDistance; + MaxDeletions = maxDeletions ?? maxTotalDistance; + MaxInsertions = maxInsertions ?? maxTotalDistance; } /// @@ -39,9 +42,9 @@ public FuzzySearchOptions(int maxSubstitutions, int maxDeletions, int maxInserti MaxTotalDistance = maxDeletions + maxInsertions + maxSubstitutions; } - public bool CanSubstitute(int currentTotalDistance, int currentSubstitutions) => (!MaxSubstitutions.HasValue || currentSubstitutions < MaxSubstitutions) && (currentTotalDistance < MaxTotalDistance); + public bool CanSubstitute(int currentTotalDistance, int currentSubstitutions) => currentSubstitutions < MaxSubstitutions && currentTotalDistance < MaxTotalDistance; - public bool CanDelete(int currentTotalDistance, int currentDeletions) => (!MaxDeletions.HasValue || currentDeletions < MaxDeletions) && (currentTotalDistance < MaxTotalDistance); + public bool CanDelete(int currentTotalDistance, int currentDeletions) => currentDeletions < MaxDeletions && currentTotalDistance < MaxTotalDistance; - public bool CanInsert(int currentTotalDistance, int currentInsertions) => (!MaxInsertions.HasValue || currentInsertions < MaxInsertions) && (currentTotalDistance < MaxTotalDistance); + public bool CanInsert(int currentTotalDistance, int currentInsertions) => currentInsertions < MaxInsertions && currentTotalDistance < MaxTotalDistance; } diff --git a/FuzzySearchNet/src/Utils.cs b/FuzzySearchNet/src/Utils.cs index 8c712f2..152f2a5 100644 --- a/FuzzySearchNet/src/Utils.cs +++ b/FuzzySearchNet/src/Utils.cs @@ -16,7 +16,7 @@ public static IEnumerable GetBestMatches(IEnumerable m { group.Add(matchesEnumerator.Current); - var match = matchesEnumerator.Current; + var matchStartIndex = matchesEnumerator.Current.StartIndex; while (matchesEnumerator.MoveNext()) { @@ -24,7 +24,7 @@ public static IEnumerable GetBestMatches(IEnumerable m if (currentMatch != null) { - if (currentMatch.StartIndex > (match.StartIndex + maxDistanece)) + if (currentMatch.StartIndex > (matchStartIndex + maxDistanece)) { yield return group.OrderBy(o => o.Distance).ThenByDescending(o => o.Match.Length).First(); group.Clear(); @@ -32,7 +32,7 @@ public static IEnumerable GetBestMatches(IEnumerable m group.Add(currentMatch); - match = currentMatch; + matchStartIndex = currentMatch.StartIndex; } } } @@ -58,7 +58,7 @@ public static async IAsyncEnumerable GetBestMatchesAsync(IAsyncEnum { group.Add(matchesEnumerator.Current); - var match = matchesEnumerator.Current; + var matchStartIndex = matchesEnumerator.Current.StartIndex; while (await matchesEnumerator.MoveNextAsync()) { @@ -66,7 +66,7 @@ public static async IAsyncEnumerable GetBestMatchesAsync(IAsyncEnum if (currentMatch != null) { - if (currentMatch.StartIndex > (match.StartIndex + maxDistanece)) + if (currentMatch.StartIndex > (matchStartIndex + maxDistanece)) { yield return group.OrderBy(o => o.Distance).ThenByDescending(o => o.Match.Length).First(); group.Clear(); @@ -74,7 +74,7 @@ public static async IAsyncEnumerable GetBestMatchesAsync(IAsyncEnum group.Add(currentMatch); - match = currentMatch; + matchStartIndex = currentMatch.StartIndex; } } }