Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

FuzzySearch

Experimental: The available options and handling of results may change in the future.

Inherits: RefCounted < Object

Provides fuzzy string searching and matching capabilities.

Description

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.

var items := ["Potion of Healing", "Greater Health Potion", "Poison Vial"]
var fuzzy := FuzzySearch.new()

for result in fuzzy.search_all("health potion", items):
    # Prints "Greater Health Potion", "Potion of Healing"
    print(result.target)

Properties

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

Methods

FuzzySearchMatch

search(query: String, target: String) const

Array[FuzzySearchMatch]

search_all(query: String, targets: PackedStringArray) const


Property Descriptions

bool case_sensitive = false 🔗

  • void set_case_sensitive(value: bool)

  • bool get_case_sensitive()

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


float filter_cutoff = 30.0 🔗

  • void set_filter_cutoff(value: float)

  • float get_filter_cutoff()

Minimum score for filtering results returned by search_all().


float filter_factor = 0.1 🔗

  • void set_filter_factor(value: float)

  • float get_filter_factor()

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


bool filter_low_scores = true 🔗

  • void set_filter_low_scores(value: bool)

  • bool get_filter_low_scores()

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.


int max_misses = 2 🔗

  • void set_max_misses(value: int)

  • int get_max_misses()

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.


int max_results = 100 🔗

  • void set_max_results(value: int)

  • int get_max_results()

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


int start_offset = 0 🔗

  • void set_start_offset(value: int)

  • int get_start_offset()

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


bool use_exact_tokens = false 🔗

  • void set_use_exact_tokens(value: bool)

  • bool get_use_exact_tokens()

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.


Method Descriptions

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


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.


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.