ktsu.FuzzySearch
1.2.2-pre.17
Prefix Reserved
See the version list below for details.
dotnet add package ktsu.FuzzySearch --version 1.2.2-pre.17
NuGet\Install-Package ktsu.FuzzySearch -Version 1.2.2-pre.17
<PackageReference Include="ktsu.FuzzySearch" Version="1.2.2-pre.17" />
<PackageVersion Include="ktsu.FuzzySearch" Version="1.2.2-pre.17" />
<PackageReference Include="ktsu.FuzzySearch" />
paket add ktsu.FuzzySearch --version 1.2.2-pre.17
#r "nuget: ktsu.FuzzySearch, 1.2.2-pre.17"
#:package ktsu.FuzzySearch@1.2.2-pre.17
#addin nuget:?package=ktsu.FuzzySearch&version=1.2.2-pre.17&prerelease
#tool nuget:?package=ktsu.FuzzySearch&version=1.2.2-pre.17&prerelease
ktsu.FuzzySearch
A lightweight .NET library that provides fuzzy string matching capabilities, allowing for approximate string matching with intelligent scoring.
Introduction
FuzzySearch is a .NET library that provides fuzzy string matching capabilities with intelligent scoring. It's perfect for implementing search-as-you-type features, command palettes, or any application requiring flexible string matching. This library offers both basic contains-style matching and more sophisticated algorithms that can rank multiple potential matches by relevance.
Features
- Fuzzy String Matching: Match strings even when they contain typos or missing characters
- Intelligent Scoring: Rank matches by quality with a smart scoring algorithm
- Case Insensitivity: Optional case-insensitive matching
- Filtering Collections: Filter lists of strings and rank results
- Customizable Parameters: Adjust matching behavior to suit different needs
- Lightweight: Minimal dependencies, focused on performance
- Well-tested: Comprehensive test suite ensuring reliability
Installation
Package Manager Console
Install-Package ktsu.FuzzySearch
.NET CLI
dotnet add package ktsu.FuzzySearch
Package Reference
<PackageReference Include="ktsu.FuzzySearch" Version="x.y.z" />
Usage Examples
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 = "Hello World";
string pattern = "hlo";
var result = Fuzzy.Match(text, pattern);
Console.WriteLine($"Is match: {result.IsMatch}"); // True
Console.WriteLine($"Score: {result.Score}"); // A value between 0-1
Console.WriteLine($"Character indices: {result.Indices}"); // Indices of matched characters
}
}
Filtering a Collection
Filter a list of strings and sort them by match quality:
using ktsu.FuzzySearch;
class Program
{
static void Main()
{
var items = new List<string>
{
"AppDataStorage",
"Application Settings",
"Data Store",
"File System",
"Storage Provider"
};
string pattern = "appstor";
// Filter and rank by match quality
var results = Fuzzy.Filter(items, pattern);
foreach (var result in results)
{
Console.WriteLine($"{result.Item} (Score: {result.Score})");
}
// Output might be:
// AppDataStorage (Score: 0.89)
// Application Settings (Score: 0.65)
// Storage Provider (Score: 0.52)
}
}
Advanced Options
Customize the matching behavior with options:
using ktsu.FuzzySearch;
class Program
{
static void Main()
{
var options = new FuzzyOptions
{
CaseSensitive = true, // Default is false
ScoreThreshold = 0.4, // Minimum score to consider a match
BonusConsecutiveChars = 1.5, // Bonus for consecutive matched characters
BonusStartOfWord = 2.0, // Bonus for matches at word boundaries
PenaltyUnmatched = 0.1, // Penalty for unmatched characters
MaxPatternLength = 64 // Maximum pattern length to consider
};
string text = "FileSystemWatcher";
string pattern = "FSW";
var result = Fuzzy.Match(text, pattern, options);
Console.WriteLine($"Score with custom options: {result.Score}");
}
}
Object Collections
Filter and match against object collections by providing a selector function:
using ktsu.FuzzySearch;
class Program
{
class FileItem
{
public string Name { get; set; }
public string Path { get; set; }
public long Size { get; set; }
}
static void Main()
{
var files = new List<FileItem>
{
new FileItem { Name = "Document.pdf", Path = "/documents/", Size = 1024 },
new FileItem { Name = "Presentation.pptx", Path = "/presentations/", Size = 2048 },
new FileItem { Name = "Spreadsheet.xlsx", Path = "/spreadsheets/", Size = 512 }
};
string pattern = "doc";
// Filter objects using a selector function
var results = Fuzzy.Filter(files, pattern, item => item.Name);
foreach (var result in results)
{
Console.WriteLine($"{result.Item.Name} (Score: {result.Score})");
}
}
}
API Reference
Fuzzy
Static Class
The main class providing fuzzy matching functionality.
Methods
Name | Parameters | Return Type | Description |
---|---|---|---|
Contains |
string text, string pattern, bool caseSensitive = false |
bool |
Checks if the text contains the pattern in sequence |
Match |
string text, string pattern, FuzzyOptions options = null |
FuzzyResult |
Matches text against pattern with scoring |
Filter |
IEnumerable<string> items, string pattern, FuzzyOptions options = null |
IEnumerable<FuzzyItem<string>> |
Filters and ranks a collection of strings |
Filter<T> |
IEnumerable<T> items, string pattern, Func<T, string> selector, FuzzyOptions options = null |
IEnumerable<FuzzyItem<T>> |
Filters and ranks a collection of objects using a selector function |
FuzzyResult
Class
Represents the result of a fuzzy match operation.
Properties
Name | Type | Description |
---|---|---|
IsMatch |
bool |
Indicates if the pattern matches the text |
Score |
double |
A value between 0 and 1 indicating match quality (1 is perfect) |
Indices |
int[] |
The indices in the text where pattern characters were matched |
FuzzyOptions
Class
Configuration options for fuzzy matching.
Properties
Name | Type | Default | Description |
---|---|---|---|
CaseSensitive |
bool |
false |
Whether matching should be case-sensitive |
ScoreThreshold |
double |
0.3 |
Minimum score required to consider a match valid |
BonusConsecutiveChars |
double |
1.0 |
Score bonus for consecutive matched characters |
BonusStartOfWord |
double |
1.5 |
Score bonus for matches at word boundaries |
PenaltyUnmatched |
double |
0.1 |
Score reduction for unmatched characters |
Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the existing coding style.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (3)
Showing the top 3 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. |
|
ktsu.Frontmatter
A .NET library for processing and manipulating YAML frontmatter in markdown files. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.2.3-pre.1 | 157 | 8/26/2025 |
1.2.2 | 199 | 8/26/2025 |
1.2.2-pre.17 | 125 | 5/20/2025 |
1.2.2-pre.15 | 84 | 5/17/2025 |
1.2.2-pre.14 | 138 | 5/16/2025 |
1.2.2-pre.13 | 205 | 5/15/2025 |
1.2.2-pre.12 | 202 | 5/14/2025 |
1.2.2-pre.11 | 206 | 5/13/2025 |
1.2.2-pre.10 | 237 | 5/12/2025 |
1.2.2-pre.9 | 167 | 5/11/2025 |
1.2.2-pre.8 | 110 | 5/10/2025 |
1.2.2-pre.7 | 58 | 5/9/2025 |
1.2.2-pre.6 | 126 | 5/8/2025 |
1.2.2-pre.5 | 125 | 5/7/2025 |
1.2.2-pre.4 | 124 | 5/6/2025 |
1.2.2-pre.3 | 123 | 5/5/2025 |
1.2.2-pre.2 | 122 | 5/4/2025 |
1.2.2-pre.1 | 127 | 5/4/2025 |
1.2.1 | 598 | 5/4/2025 |
1.2.1-pre.2 | 63 | 4/26/2025 |
1.2.1-pre.1 | 120 | 4/4/2025 |
1.2.0 | 1,203 | 3/30/2025 |
1.1.0 | 171 | 3/30/2025 |
1.0.14-pre.3 | 82 | 2/6/2025 |
1.0.14-pre.2 | 69 | 2/5/2025 |
1.0.14-pre.1 | 75 | 2/5/2025 |
1.0.13 | 1,964 | 1/2/2025 |
1.0.13-pre.29 | 75 | 2/3/2025 |
1.0.13-pre.28 | 72 | 2/3/2025 |
1.0.13-pre.27 | 78 | 2/1/2025 |
1.0.13-pre.26 | 71 | 1/30/2025 |
1.0.13-pre.25 | 71 | 1/28/2025 |
1.0.13-pre.24 | 71 | 1/26/2025 |
1.0.13-pre.23 | 65 | 1/24/2025 |
1.0.13-pre.22 | 72 | 1/22/2025 |
1.0.13-pre.21 | 69 | 1/20/2025 |
1.0.13-pre.20 | 61 | 1/18/2025 |
1.0.13-pre.19 | 62 | 1/16/2025 |
1.0.13-pre.18 | 49 | 1/14/2025 |
1.0.13-pre.17 | 60 | 1/13/2025 |
1.0.13-pre.16 | 66 | 1/11/2025 |
1.0.13-pre.15 | 57 | 1/10/2025 |
1.0.13-pre.14 | 69 | 1/10/2025 |
1.0.13-pre.13 | 65 | 1/8/2025 |
1.0.13-pre.12 | 70 | 1/7/2025 |
1.0.13-pre.11 | 76 | 1/6/2025 |
1.0.13-pre.10 | 89 | 1/4/2025 |
1.0.13-pre.9 | 71 | 1/3/2025 |
1.0.13-pre.8 | 74 | 1/3/2025 |
1.0.13-pre.7 | 85 | 1/3/2025 |
1.0.13-pre.6 | 80 | 1/2/2025 |
1.0.13-pre.5 | 95 | 12/31/2024 |
1.0.13-pre.4 | 72 | 12/29/2024 |
1.0.13-pre.3 | 70 | 12/28/2024 |
1.0.13-pre.2 | 76 | 12/27/2024 |
1.0.13-pre.1 | 71 | 12/27/2024 |
1.0.12-pre.1 | 68 | 12/27/2024 |
1.0.11 | 907 | 12/26/2024 |
1.0.10 | 110 | 12/26/2024 |
1.0.10-pre.1 | 69 | 12/27/2024 |
1.0.9 | 108 | 12/26/2024 |
1.0.8 | 107 | 12/26/2024 |
1.0.7 | 112 | 12/26/2024 |
1.0.6 | 116 | 12/26/2024 |
1.0.5 | 116 | 12/26/2024 |
1.0.4 | 990 | 12/23/2024 |
1.0.3 | 107 | 12/23/2024 |
1.0.2 | 193 | 12/22/2024 |
1.0.1 | 176 | 12/22/2024 |
1.0.0 | 678 | 12/4/2024 |
1.0.0-alpha.18 | 219 | 12/2/2024 |
1.0.0-alpha.17 | 134 | 11/30/2024 |
1.0.0-alpha.16 | 182 | 11/26/2024 |
1.0.0-alpha.15 | 221 | 11/20/2024 |
1.0.0-alpha.14 | 245 | 11/13/2024 |
1.0.0-alpha.13 | 443 | 11/1/2024 |
1.0.0-alpha.12 | 600 | 10/15/2024 |
1.0.0-alpha.11 | 357 | 10/4/2024 |
1.0.0-alpha.10 | 462 | 9/19/2024 |
1.0.0-alpha.9 | 121 | 9/19/2024 |
1.0.0-alpha.8 | 62 | 9/19/2024 |
1.0.0-alpha.7 | 93 | 9/19/2024 |
1.0.0-alpha.6 | 90 | 9/18/2024 |
1.0.0-alpha.5 | 73 | 9/18/2024 |
1.0.0-alpha.4 | 169 | 9/18/2024 |
1.0.0-alpha.3 | 112 | 9/18/2024 |
1.0.0-alpha.2 | 288 | 9/14/2024 |
1.0.0-alpha.1 | 74 | 9/14/2024 |
## v1.2.2-pre.17
Initial release or repository with no prior history.