Delphi/FreePascal implementation of the fts_fuzzy_match algorithm, ported by j.visser and tweaked by @forever-new.
Original code taken from j.visser's public GitHub Gist (commit ebe9842d, 2020-11-02).
Table of Contents
FuzzyScore.dpr
uFuzzyMatching.pas
Test.dpr
— algorithm test code.test_results.txt
— test results.
The original port of the algorithm was slightly adapted by j.visser for his own use, especially:
- Calculation corrected for double byte chars.
- Added a match index offset of 1 to match Delphi/Pascal string indexes.
@forever-new tweaked the original code to align it with the needs of this project, enforcing the behaviour of the original algorithm, and added the algorithm validation test code, and contributed the changes in PR #19:
- Added check for non-uppercaseable characters. e.g. numbers — so 'a4' doesn't get camel case bonus.
2, Removed extra Delphi index
pascal_index = 1
— it broke the score calculation in a couple of places. - Removed update for double byte chars — it was causing wrong calculation of unmatched count, and other issues.
- Added initialization for internal static array so the output Matches array is not populated with memory garbage.
- Set option
first_letter_count
to 1, to align with other ports. - Added test algorithm.
Can be used in Delphi, or in FreePascal in Delphi or ObjFPC mode.
fpc -Mdelphi FuzzyScore.pp
FuzzyScore [search string] [ < input ]
CC0, Creative Commons Zero, (public domain).