diff options
author | 2019-01-14 00:44:46 +1100 | |
---|---|---|
committer | 2019-01-14 00:44:46 +1100 | |
commit | 3d84943f72df5d69db5e5cff1d71887fcc23c422 (patch) | |
tree | 893bbfe9575c70b5b95311642937bc92bfb633ba /src/frontend/mame/ui/selsoft.cpp | |
parent | 9d7b4d0faa64f42665b1c19b28b5eb15c0f40d29 (diff) |
Make search not suck as badly (use algorithm derived from Jaro-Winkler similarity to match search strings, match on more useful stuff)
Diffstat (limited to 'src/frontend/mame/ui/selsoft.cpp')
-rw-r--r-- | src/frontend/mame/ui/selsoft.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index e7ebc3effa2..e1eb1f75c33 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -490,15 +490,20 @@ void menu_select_software::load_sw_custom_filters() void menu_select_software::find_matches(const char *str, int count) { // allocate memory to track the penalty value - std::vector<int> penalty(count, 9999); - int index = 0; + std::vector<double> penalty(count, 1.0); + std::u32string const search(ustr_from_utf8(normalize_unicode(str, unicode_normalization_form::D, true))); - for (; index < m_displaylist.size(); ++index) + int index = 0; + for ( ; index < m_displaylist.size(); ++index) { - // pick the best match between driver name and description - int curpenalty = fuzzy_substring(str, m_displaylist[index]->longname); - int tmp = fuzzy_substring(str, m_displaylist[index]->shortname); - curpenalty = std::min(curpenalty, tmp); + // pick the best match between shortname and longname + // TODO: search alternate title as well + double curpenalty(util::edit_distance(search, ustr_from_utf8(normalize_unicode(m_displaylist[index]->shortname, unicode_normalization_form::D, true)))); + if (curpenalty) + { + double const tmp(util::edit_distance(search, ustr_from_utf8(normalize_unicode(m_displaylist[index]->longname, unicode_normalization_form::D, true)))); + curpenalty = (std::min)(curpenalty, tmp); + } // insert into the sorted table of matches for (int matchnum = count - 1; matchnum >= 0; --matchnum) |