Fuzzy Search In Games?

Godot Version

Replace this line with your Godot version

Question

Hellooooooooooo!
This is going to be sort of weird, i dont know if im phrasing my quiestion correct but here goes.

I want to have my charecter be able to look at a stack of something, and the player can search something in there, but it wouldnt need to be exact (fuzzy search). Is there any way i can do that without having to put the multitude of different variations in and running a check for each one? Is there just a simple way to enable fuzzy search so the charecter can search for the name of something but not get it exact? (i only want to be able to search for a few things, and id give the player hints on what to type)

I find String’s is_subsequence_ofn to be a good fuzzy-ish search function

such as

item.visible = search_query.is_subsequence_ofn(item.name)

Godot’s String also has similarity() function that can help with fuzzy search. You can put all candidates into an array and sort it by similarity.

1 Like

You can also just implement a fuzzy string search function yourself if you want, there’s plenty of tutorials for it in other programming languages.