ktsu.FuzzySearch
1.2.0
Prefix Reserved
See the version list below for details.
dotnet add package ktsu.FuzzySearch --version 1.2.0
NuGet\Install-Package ktsu.FuzzySearch -Version 1.2.0
<PackageReference Include="ktsu.FuzzySearch" Version="1.2.0" />
<PackageVersion Include="ktsu.FuzzySearch" Version="1.2.0" />
<PackageReference Include="ktsu.FuzzySearch" />
paket add ktsu.FuzzySearch --version 1.2.0
#r "nuget: ktsu.FuzzySearch, 1.2.0"
#addin nuget:?package=ktsu.FuzzySearch&version=1.2.0
#tool nuget:?package=ktsu.FuzzySearch&version=1.2.0
ktsu.FuzzySearch
A lightweight .NET library that provides fuzzy string matching capabilities, allowing for approximate string matching with intelligent scoring. It's perfect for implementing search-as-you-type features, command palettes, or any application requiring flexible string matching.
Installation
To install FuzzySearch, you can use the .NET CLI:
dotnet add package ktsu.FuzzySearch
Or you can use the NuGet Package Manager in Visual Studio to search for and install the ktsu.FuzzySearch
package.
Usage
Basic Matching
The simplest way to check if a string contains characters from a pattern in sequence:
using ktsu.FuzzySearch;
class Program
{
static void Main()
{
string text = "Hello World"; string pattern = "hlo";
bool isMatch = Fuzzy.Contains(text, pattern); // Returns true
}
}
Matching with Scoring
To get both a match result and a score that indicates the quality of the match:
using ktsu.FuzzySearch;
class Program
{
static void Main()
{
string text = "FuzzyStringMatcher";
string pattern = "fzm";
bool isMatch = Fuzzy.Contains(text, pattern, out int score);
// isMatch will be true
// score will contain a value reflecting match quality, with positive values indicating a better match
Console.WriteLine($"Match found: {isMatch}, Score: {score}");
}
}
Implementing Search Features
FuzzySearch is ideal for implementing searchable lists or command palettes:
using ktsu.FuzzySearch;
using System.Linq;
class Program
{
static void Main()
{
var items = new[]
{
"ApplicationSettings",
"UserPreferences",
"SecurityOptions",
"AccountManagement",
"SystemConfiguration"
};
string searchTerm = "set";
// Find matches and order by score (best matches first)
var matches = items
.Select(item => new
{
Item = item,
IsMatch = Fuzzy.Contains(item, searchTerm, out int score),
Score = score
})
.Where(result => result.IsMatch)
.OrderByDescending(result => result.Score);
foreach (var match in matches)
{
Console.WriteLine($"{match.Item}: {match.Score}");
}
// Output will prioritize "ApplicationSettings" over other matches
}
}
Scoring System
The library uses a scoring system that rewards:
- Consecutive character matches - Characters that appear adjacent to each other in the pattern and subject receive a bonus
- Matches after separators - Characters that appear after
_
or space characters receive a bonus - CamelCase boundary matches - Characters that appear at camelCase boundaries receive a bonus
Meanwhile, penalties are applied for:
- Unmatched characters - Characters that are not found in the pattern receive a penalty
API Reference
Fuzzy Class
bool Contains(string subject, string pattern)
: Determines if the subject string contains all characters from the pattern in sequence.bool Contains(string subject, string pattern, out int score)
: Determines if the subject contains all pattern characters and provides a match quality score.
Case Sensitivity
All matching operations are case-insensitive, making the library more forgiving and user-friendly for search scenarios.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Acknowledgements
Thanks to the .NET community and ktsu.dev contributors for their support.
This library was adapted from the implementation posted by Collin Dillinger.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ktsu.FuzzySearch:
Package | Downloads |
---|---|
ktsu.ImGuiWidgets
A library of custom widgets using ImGui.NET and utilities to enhance ImGui-based applications. |
|
ktsu.TextFilter
A library providing methods for matching and filtering text. It supports glob patterns, regular expressions, and fuzzy matching. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.1-pre.1 | 104 | 4/4/2025 |
1.2.0 | 460 | 3/30/2025 |
1.1.0 | 139 | 3/30/2025 |
1.0.14-pre.3 | 69 | 2/6/2025 |
1.0.14-pre.2 | 57 | 2/5/2025 |
1.0.14-pre.1 | 60 | 2/5/2025 |
1.0.13 | 1,778 | 1/2/2025 |
1.0.13-pre.29 | 57 | 2/3/2025 |
1.0.13-pre.28 | 55 | 2/3/2025 |
1.0.13-pre.27 | 60 | 2/1/2025 |
1.0.13-pre.26 | 56 | 1/30/2025 |
1.0.13-pre.25 | 54 | 1/28/2025 |
1.0.13-pre.24 | 55 | 1/26/2025 |
1.0.13-pre.23 | 49 | 1/24/2025 |
1.0.13-pre.22 | 55 | 1/22/2025 |
1.0.13-pre.21 | 51 | 1/20/2025 |
1.0.13-pre.20 | 46 | 1/18/2025 |
1.0.13-pre.19 | 45 | 1/16/2025 |
1.0.13-pre.18 | 33 | 1/14/2025 |
1.0.13-pre.17 | 45 | 1/13/2025 |
1.0.13-pre.16 | 50 | 1/11/2025 |
1.0.13-pre.15 | 43 | 1/10/2025 |
1.0.13-pre.14 | 48 | 1/10/2025 |
1.0.13-pre.13 | 46 | 1/8/2025 |
1.0.13-pre.12 | 55 | 1/7/2025 |
1.0.13-pre.11 | 61 | 1/6/2025 |
1.0.13-pre.10 | 73 | 1/4/2025 |
1.0.13-pre.9 | 57 | 1/3/2025 |
1.0.13-pre.8 | 59 | 1/3/2025 |
1.0.13-pre.7 | 67 | 1/3/2025 |
1.0.13-pre.6 | 66 | 1/2/2025 |
1.0.13-pre.5 | 79 | 12/31/2024 |
1.0.13-pre.4 | 57 | 12/29/2024 |
1.0.13-pre.3 | 54 | 12/28/2024 |
1.0.13-pre.2 | 57 | 12/27/2024 |
1.0.13-pre.1 | 56 | 12/27/2024 |
1.0.12-pre.1 | 53 | 12/27/2024 |
1.0.11 | 881 | 12/26/2024 |
1.0.10 | 92 | 12/26/2024 |
1.0.10-pre.1 | 53 | 12/27/2024 |
1.0.9 | 88 | 12/26/2024 |
1.0.8 | 88 | 12/26/2024 |
1.0.7 | 92 | 12/26/2024 |
1.0.6 | 99 | 12/26/2024 |
1.0.5 | 99 | 12/26/2024 |
1.0.4 | 974 | 12/23/2024 |
1.0.3 | 90 | 12/23/2024 |
1.0.2 | 178 | 12/22/2024 |
1.0.1 | 157 | 12/22/2024 |
1.0.0 | 657 | 12/4/2024 |
1.0.0-alpha.18 | 199 | 12/2/2024 |
1.0.0-alpha.17 | 120 | 11/30/2024 |
1.0.0-alpha.16 | 168 | 11/26/2024 |
1.0.0-alpha.15 | 207 | 11/20/2024 |
1.0.0-alpha.14 | 225 | 11/13/2024 |
1.0.0-alpha.13 | 426 | 11/1/2024 |
1.0.0-alpha.12 | 585 | 10/15/2024 |
1.0.0-alpha.11 | 343 | 10/4/2024 |
1.0.0-alpha.10 | 448 | 9/19/2024 |
1.0.0-alpha.9 | 103 | 9/19/2024 |
1.0.0-alpha.8 | 47 | 9/19/2024 |
1.0.0-alpha.7 | 73 | 9/19/2024 |
1.0.0-alpha.6 | 68 | 9/18/2024 |
1.0.0-alpha.5 | 60 | 9/18/2024 |
1.0.0-alpha.4 | 151 | 9/18/2024 |
1.0.0-alpha.3 | 96 | 9/18/2024 |
1.0.0-alpha.2 | 269 | 9/14/2024 |
1.0.0-alpha.1 | 61 | 9/14/2024 |
## v1.2.0 (minor)
Changes since v1.1.0:
- Refactor Fuzzy matching methods for performance ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.1.0 (minor)
Changes since v1.0.0:
- [minor] Fix typo in make-license.ps1 ([@matt-edmondson](https://github.com/matt-edmondson))
- Add automation scripts for metadata generation and project management ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance fuzzy search library and add unit tests ([@matt-edmondson](https://github.com/matt-edmondson))
- Renamed metadata files ([@matt-edmondson](https://github.com/matt-edmondson))
- Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.7 (patch)
Changes since v1.0.6:
- Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.0 (major)
Changes since 0.0.0.0:
- Add github package support ([@matt-edmondson](https://github.com/matt-edmondson))
- Initial commit ([@matt-edmondson](https://github.com/matt-edmondson))
- Migrate ktsu.io to ktsu namespace ([@matt-edmondson](https://github.com/matt-edmondson))
- Update build config ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.props ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.targets ([@matt-edmondson](https://github.com/matt-edmondson))
- Update dotnet.yml ([@matt-edmondson](https://github.com/matt-edmondson))
- Update LICENSE ([@matt-edmondson](https://github.com/matt-edmondson))
- Update nuget.config ([@matt-edmondson](https://github.com/matt-edmondson))