--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local TS = _G[script] local CharAt = TS.import(script, script.Parent.Parent, "Utils", "CharAt") local function FuzzyScoreScore(term, query) local term_lower = string.lower(term) local query_lower = string.lower(query) local score = 0 local term_index = 0 local previous_matched_index = -1 for query_char in string.gmatch(query_lower, utf8.charpattern) do local found = false -- Search term from current position onwards do local _shouldIncrement = false while true do if _shouldIncrement then term_index += 1 else _shouldIncrement = true end if not (term_index < #term_lower) then break end if CharAt(term_lower, term_index) == query_char then -- Base point for match score += 1 -- Bonus for consecutive matches if previous_matched_index == term_index - 1 then score += 2 end previous_matched_index = term_index term_index += 1 found = true break end end end if not found then return 0 end end return score end return { FuzzyScoreScore = FuzzyScoreScore, }