A Lua port of fzy's fuzzy string matching algorithm. This includes both a pure Lua implementation and a compiled C implementation with a Lua wrapper.
From the original fzy:
fzy is faster and shows better results than other fuzzy finders.
Most other fuzzy matchers sort based on the length of a match. fzy tries to find the result the user intended. It does this by favouring matches on consecutive letters and starts of words. This allows matching using acronyms or different parts of the path.
luarocks install fzyOr, just download a copy of fzy_lua.lua and drop it in your project.
score(needle, haystack)
local fzy = require('fzy')
fzy.score("amuser", "app/models/user.rb") -- 5.595
fzy.score("amuser", "app/models/customer.rb") -- 3.655positions(needle, haystack)
fzy.positions("amuser", "app/models/user.rb") -- { 1, 5, 12, 13, 14, 15 }
-- ^ ^ ^^^^
fzy.positions("amuser", "app/models/customer.rb") -- { 1, 5, 13, 14, 18, 19 }
-- ^ ^ ^^ ^^NB: score and positions should only be called with a needle that is a
subsequence of the haystack, which you can check with the has_match
function.
See the docs for more information.
busted test/test.luaJohn Hawthorn wrote the original fzy. The native implementation here is
basically his code with a few tweaks, and the lua implementation is derived
from his fzy.js implementation.
Rom Grk made several useful suggestions, and has a
lua C implemenation using
the luajit ffi library.