FuzzySearch
Provides fuzzy string searching and matching capabilities.
Provides fuzzy string searching and matching capabilities.
The fuzzy search algorithm is designed to find target strings which mostly match a query string while allowing for breaks, typos, and out of order matches.
string[] items = ["Potion of Healing", "Greater Health Potion", "Poison Vial"];
FuzzySearch fuzzy = new();
foreach (var result in fuzzy.SearchAll("health potion", items))
{
// Prints "Greater Health Potion", "Potion of Healing"
ReckfellApi.Print(result.Target);
}Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
FuzzySearchConstructor
public FuzzySearch();Properties8
CaseSensitiveProperty
public bool CaseSensitive { get; set; }Whether the query character casing should be matched exactly or not.
FilterCutoffProperty
public float FilterCutoff { get; set; }Minimum score for filtering results returned by FuzzySearch.SearchAll.
FilterFactorProperty
public float FilterFactor { get; set; }Biases the filtering cutoff score between the average score and max score. Value should be between 0 and 1.
FilterLowScoresProperty
public bool FilterLowScores { get; set; }If true, lower quality matches are not returned by FuzzySearch.SearchAll. The default filtering behavior is tuned to keep exact matches and reject significantly broken up matches. Setting this to false can potentially improve results when searching a small number of items.
MaxMissesProperty
public int MaxMisses { get; set; }Maximum number of non-matched characters in the query before skipping a target as non-matching. This option is ignored if FuzzySearch.UseExactTokens is true.
MaxResultsProperty
public int MaxResults { get; set; }Maximum number of results which can be returned by FuzzySearch.SearchAll.
StartOffsetProperty
public int StartOffset { get; set; }Number of leading characters to omit from matching. For example, this can be used to skip a common prefix such as asset://.
UseExactTokensProperty
public bool UseExactTokens { get; set; }If true, only targets which contain each token as a non-overlapping substring are returned. Gaps and missed characters are not considered valid matches, but FuzzySearch.CaseSensitive is still used.
Methods19
GetCaseSensitivebool
public bool GetCaseSensitive();boolGetFilterCutofffloat
public float GetFilterCutoff();floatGetFilterFactorfloat
public float GetFilterFactor();floatGetFilterLowScoresbool
public bool GetFilterLowScores();boolGetMaxMissesint
public int GetMaxMisses();intGetMaxResultsint
public int GetMaxResults();intGetStartOffsetint
public int GetStartOffset();intGetUseExactTokensbool
public bool GetUseExactTokens();boolSearchFuzzySearchMatch
public FuzzySearchMatch Search(string query, string target);Searches the target for query, returning a FuzzySearchMatch instance on success or null otherwise.
| Name | Type | Default |
|---|---|---|
query | string | — |
target | string | — |
FuzzySearchMatchSearchAll2 overloads
public Reckfell.Collections.Array<FuzzySearchMatch> SearchAll(string query, ReadOnlySpan<string> targets);Searches all of targets for query and returns up to the top FuzzySearch.MaxResults scoring values. The results are sorted by score in descending order. Low quality results are removed if FuzzySearch.FilterLowScores is true.
| Name | Type | Default |
|---|---|---|
query | string | — |
targets | ReadOnlySpan<string> | — |
Reckfell.Collections.Array<FuzzySearchMatch>public Reckfell.Collections.Array<FuzzySearchMatch> SearchAll(string query, string[] targets);Searches all of targets for query and returns up to the top FuzzySearch.MaxResults scoring values. The results are sorted by score in descending order. Low quality results are removed if FuzzySearch.FilterLowScores is true.
| Name | Type | Default |
|---|---|---|
query | string | — |
targets | string[] | — |
Reckfell.Collections.Array<FuzzySearchMatch>SetCaseSensitivevoid
public void SetCaseSensitive(bool caseSensitive);| Name | Type | Default |
|---|---|---|
caseSensitive | bool | — |
SetFilterCutoffvoid
public void SetFilterCutoff(float filterCutoff);| Name | Type | Default |
|---|---|---|
filterCutoff | float | — |
SetFilterFactorvoid
public void SetFilterFactor(float filterFactor);| Name | Type | Default |
|---|---|---|
filterFactor | float | — |
SetFilterLowScoresvoid
public void SetFilterLowScores(bool filterLowScores);| Name | Type | Default |
|---|---|---|
filterLowScores | bool | — |
SetMaxMissesvoid
public void SetMaxMisses(int maxMisses);| Name | Type | Default |
|---|---|---|
maxMisses | int | — |
SetMaxResultsvoid
public void SetMaxResults(int maxResults);| Name | Type | Default |
|---|---|---|
maxResults | int | — |
SetStartOffsetvoid
public void SetStartOffset(int startOffset);| Name | Type | Default |
|---|---|---|
startOffset | int | — |
SetUseExactTokensvoid
public void SetUseExactTokens(bool useExactTokens);| Name | Type | Default |
|---|---|---|
useExactTokens | bool | — |