Skip to content

Commit

Permalink
fix(user_dictionary): exact match phrase in front
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Nov 11, 2024
1 parent 0cf0e63 commit c067da2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/rime/dict/user_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,20 @@ an<UserDictEntryCollector> 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);
}
}
}
}
Expand Down

0 comments on commit c067da2

Please sign in to comment.