Skip to content

FuzzySearch

Inherits: RefCounted < Object

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"
Orb.Print(result.Target);
}
Type Name Default
bool case_sensitive false
float filter_cutoff 30.0
float filter_factor 0.1
bool filter_low_scores true
int max_misses 2
int max_results 100
int start_offset 0
bool use_exact_tokens false
Returns Method
FuzzySearchMatch search(query: String, target: String) const
Array[FuzzySearchMatch] search_all(query: String, targets: PackedStringArray) const

case_sensitive

bool case_sensitive = false

Whether the query character casing should be matched exactly or not.

filter_cutoff

float filter_cutoff = 30.0

Minimum score for filtering results returned by search_all().

filter_factor

float filter_factor = 0.1

Biases the filtering cutoff score between the average score and max score. Value should be between 0 and 1.

filter_low_scores

bool filter_low_scores = true

If true, lower quality matches are not returned by search_all(). 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.

max_misses

int max_misses = 2

Maximum number of non-matched characters in the query before skipping a target as non-matching. This option is ignored if use_exact_tokens is true.

max_results

int max_results = 100

Maximum number of results which can be returned by search_all().

start_offset

int start_offset = 0

Number of leading characters to omit from matching. For example, this can be used to skip a common prefix such as res://.

use_exact_tokens

bool use_exact_tokens = false

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 case_sensitive is still used.

FuzzySearchMatch search(query: String, target: String) const

Searches the target for query, returning a FuzzySearchMatch instance on success or null otherwise.

search_all

Array[FuzzySearchMatch] search_all(query: String, targets: PackedStringArray) const

Searches all of targets for query and returns up to the top max_results scoring values. The results are sorted by score in descending order. Low quality results are removed if filter_low_scores is true.