From 6f85a7d3fd1f9581652e94f4528ac5d418f6bcd3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 26 Jan 2021 21:32:44 +0100 Subject: [PATCH] Fix of #5202 - Fuzzy Search engine is too fuzzy * changed evaluation coefficients inside fuzzy_match_recursive * don't add markers to the labels before it's used in fuzzy_match_recursive + follow-up https://github.com/prusa3d/PrusaSlicer/commit/78a3d8b63eb024f66a21274b828e5891b68f779c - added missed fix for one more line (use std::towlower instead of std::tolower for wchar_t) Problem was appearance on Cyrillic languages --- src/slic3r/GUI/Search.cpp | 23 +++++++++++++---------- src/slic3r/GUI/fts_fuzzy_match.h | 6 +++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index d61fc05e0..738d5e435 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -124,11 +124,12 @@ static wxString wrap_string(const wxString& str) } // Mark a string using ColorMarkerStart and ColorMarkerEnd symbols -static std::wstring mark_string(const std::wstring &str, const std::vector &matches) +static std::wstring mark_string(const std::wstring &str, const std::vector &matches, Preset::Type type, PrinterTechnology pt) { std::wstring out; + out += marker_by_type(type, pt); if (matches.empty()) - out = str; + out += str; else { out.reserve(str.size() * 2); if (matches.front() > 0) @@ -181,10 +182,11 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) bool full_list = search.empty(); std::wstring sep = L" : "; - auto get_label = [this, &sep](const Option& opt) + auto get_label = [this, &sep](const Option& opt, bool marked = true) { std::wstring out; - out += marker_by_type(opt.type, printer_technology); + if (marked) + out += marker_by_type(opt.type, printer_technology); const std::wstring *prev = nullptr; for (const std::wstring * const s : { view_params.category ? &opt.category_local : nullptr, @@ -198,10 +200,11 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) return out; }; - auto get_label_english = [this, &sep](const Option& opt) + auto get_label_english = [this, &sep](const Option& opt, bool marked = true) { std::wstring out; - out += marker_by_type(opt.type, printer_technology); + if (marked) + out += marker_by_type(opt.type, printer_technology); const std::wstring*prev = nullptr; for (const std::wstring * const s : { view_params.category ? &opt.category : nullptr, @@ -234,8 +237,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) std::wstring wsearch = boost::nowide::widen(search); boost::trim_left(wsearch); - std::wstring label = get_label(opt); - std::wstring label_english = get_label_english(opt); + std::wstring label = get_label(opt, false); + std::wstring label_english = get_label_english(opt, false); int score = std::numeric_limits::min(); int score2; matches.clear(); @@ -252,8 +255,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) matches = std::move(matches2); score = score2; } - if (score > std::numeric_limits::min()) { - label = mark_string(label, matches); + if (score > 90/*std::numeric_limits::min()*/) { + label = mark_string(label, matches, opt.type, printer_technology); label += L" [" + std::to_wstring(score) + L"]";// add score value std::string label_u8 = into_u8(label); std::string label_plain = label_u8; diff --git a/src/slic3r/GUI/fts_fuzzy_match.h b/src/slic3r/GUI/fts_fuzzy_match.h index 4dd206aac..4b474451c 100644 --- a/src/slic3r/GUI/fts_fuzzy_match.h +++ b/src/slic3r/GUI/fts_fuzzy_match.h @@ -113,7 +113,7 @@ namespace fts { bool first_match = true; while (*pattern != '\0' && *str != '\0') { - int num_matched = std::tolower(*pattern) == std::tolower(*str) ? 1 : 0; + int num_matched = std::towlower(*pattern) == std::towlower(*str) ? 1 : 0; bool folded_match = false; if (! num_matched) { wchar_t tmp[4]; @@ -168,11 +168,11 @@ namespace fts { // Calculate score if (matched) { static constexpr int sequential_bonus = 15; // bonus for adjacent matches - static constexpr int separator_bonus = 30; // bonus if match occurs after a separator + static constexpr int separator_bonus = 10/*30*/; // bonus if match occurs after a separator static constexpr int camel_bonus = 30; // bonus if match is uppercase and prev is lower static constexpr int first_letter_bonus = 15; // bonus if the first letter is matched - static constexpr int leading_letter_penalty = -5; // penalty applied for every letter in str before the first match + static constexpr int leading_letter_penalty = -1/*-5*/; // penalty applied for every letter in str before the first match static constexpr int max_leading_letter_penalty = -15; // maximum penalty for leading letters static constexpr int unmatched_letter_penalty = -1; // penalty for every letter that doesn't matter