Gui search engine?

So Im trying to make a gui inventory system where the player can search up there pets by name, and was wondering how I could accomplish this? Also, How do I also find the closest result to what the player is looking for, Ex: the player searches “Do”, and you return “Dog” basically a autocomplete system. I see this type of system in very popular games such as bubble gum sim, pet sim etc, which made me curious on how they do it?

1 Like

I’m not sure if this method is used in popular games but I’d personally use when working with fuzzy searching. The Levenshtein Algorithm is used for doing a fuzzy search on a string and can help find partial matches. This GitHub has the algorithm in Lua. What I would do is iterate over every item in the inventory and find the Levenshtein distance between the searched string and the item’s name. I would then put these items into another table and sort this table from least to greatest in terms of their distance and display the table in this order to the user. If you want you can apply a threshold to this table making the number of items displayed smaller.

13 Likes