From c067da289d2f8de29c38ae5f1410f8d658b6e8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E6=88=8E=E6=B0=8F?= Date: Mon, 11 Nov 2024 22:07:29 +0800 Subject: [PATCH] fix(user_dictionary): exact match phrase in front --- src/rime/dict/user_dictionary.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/rime/dict/user_dictionary.cc b/src/rime/dict/user_dictionary.cc index 0387b05a6..b5f0acaeb 100644 --- a/src/rime/dict/user_dictionary.cc +++ b/src/rime/dict/user_dictionary.cc @@ -326,20 +326,20 @@ an UserDictionary::Lookup( return nullptr; // sort each group of homophones by weight for (auto& v : state.query_result) { - v.second.Sort(); - } - auto entries_with_word_completion = - state.query_result.find(state.predict_word_from_depth); - if (entries_with_word_completion != state.query_result.end()) { - auto& entries = entries_with_word_completion->second; - // if the top candidate is predictive match, - if (!entries.empty() && entries.front()->IsPredictiveMatch()) { - auto found = - std::find_if(entries.begin(), entries.end(), - [](const auto& e) { return e->IsExactMatch(); }); - if (found != entries.end()) { - // move the first exact match candidate to top. - std::rotate(entries.begin(), found, found + 1); + auto& entries = v.second; + entries.Sort(); + if (state.predict_word_from_depth) { + if (!entries.empty() && entries.front()->IsPredictiveMatch()) { + DLOG(INFO) << "front entry is predictive match: " + << entries.front()->text; + auto found = + std::find_if(entries.begin(), entries.end(), + [](const auto& e) { return e->IsExactMatch(); }); + if (found != entries.end()) { + DLOG(INFO) << "rotating exact match entry to front: " + << (*found)->text; + std::rotate(entries.begin(), found, found + 1); + } } } }