ktsu.FuzzySearch
1.2.37
Prefix Reserved
dotnet add package ktsu.FuzzySearch --version 1.2.37
NuGet\Install-Package ktsu.FuzzySearch -Version 1.2.37
<PackageReference Include="ktsu.FuzzySearch" Version="1.2.37" />
<PackageVersion Include="ktsu.FuzzySearch" Version="1.2.37" />
<PackageReference Include="ktsu.FuzzySearch" />
paket add ktsu.FuzzySearch --version 1.2.37
#r "nuget: ktsu.FuzzySearch, 1.2.37"
#:package ktsu.FuzzySearch@1.2.37
#addin nuget:?package=ktsu.FuzzySearch&version=1.2.37
#tool nuget:?package=ktsu.FuzzySearch&version=1.2.37
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 | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
- System.Threading.Tasks.Extensions (>= 4.6.3)
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
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.TextFilter
A library providing methods for matching and filtering text. It supports glob patterns, regular expressions, and fuzzy matching. |
|
|
ktsu.ImGuiWidgets
A library of custom widgets using ImGui.NET and utilities to enhance ImGui-based applications. |
|
|
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.37 | 67 | 8/21/2026 |
| 1.2.36 | 138 | 8/20/2026 |
| 1.2.35 | 437 | 8/19/2026 |
| 1.2.34 | 129 | 8/18/2026 |
| 1.2.33 | 591 | 8/17/2026 |
| 1.2.32 | 1,234 | 8/7/2026 |
| 1.2.31 | 111 | 8/6/2026 |
| 1.2.30 | 273 | 8/5/2026 |
| 1.2.29 | 858 | 7/28/2026 |
| 1.2.28 | 794 | 7/22/2026 |
| 1.2.27 | 851 | 7/15/2026 |
| 1.2.26 | 282 | 7/14/2026 |
| 1.2.25 | 891 | 7/9/2026 |
| 1.2.24 | 888 | 7/1/2026 |
| 1.2.23 | 323 | 6/30/2026 |
| 1.2.22 | 329 | 6/29/2026 |
| 1.2.21 | 317 | 6/28/2026 |
| 1.2.20 | 120 | 6/28/2026 |
| 1.2.19 | 374 | 6/25/2026 |
| 1.2.18 | 170 | 6/22/2026 |
## v1.2.37 (patch)
Changes since v1.2.36:
- Bump the ktsu group with 9 updates ([@dependabot[bot]](https://github.com/dependabot[bot]))