33 if (query.empty())
return 0;
39 std::string text_lower = text;
40 std::string query_lower = query;
41 std::transform(text_lower.begin(), text_lower.end(), text_lower.begin(), ::tolower);
42 std::transform(query_lower.begin(), query_lower.end(), query_lower.begin(), ::tolower);
45 if (text_lower == query_lower)
return 1000;
48 if (text_lower.find(query_lower) == 0)
return 500;
51 if (text_lower.find(query_lower) != std::string::npos)
return 250;
54 while (text_idx < text_lower.length() && query_idx < query_lower.length()) {
55 if (text_lower[text_idx] == query_lower[query_idx]) {
63 if (query_idx != query_lower.length())
return 0;
69 std::vector<std::pair<int, CommandEntry>> scored;
71 for (
const auto& [name, entry] :
commands_) {
75 score +=
FuzzyScore(entry.category, query) / 2;
76 score +=
FuzzyScore(entry.description, query) / 4;
79 score += entry.usage_count * 2;
81 auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
82 std::chrono::system_clock::now().time_since_epoch()).count();
83 int64_t age_ms = now_ms - entry.last_used_ms;
86 }
else if (age_ms < 3600000) {
91 scored.push_back({score, entry});
96 std::sort(scored.begin(), scored.end(),
97 [](
const auto& a,
const auto& b) { return a.first > b.first; });
99 std::vector<CommandEntry> results;
100 for (
const auto& [score, entry] : scored) {
101 results.push_back(entry);
108 std::vector<CommandEntry> recent;
110 for (
const auto& [name, entry] :
commands_) {
111 if (entry.usage_count > 0) {
112 recent.push_back(entry);
116 std::sort(recent.begin(), recent.end(),
118 return a.last_used_ms > b.last_used_ms;
121 if (recent.size() >
static_cast<size_t>(limit)) {
122 recent.resize(limit);
129 std::vector<CommandEntry> frequent;
131 for (
const auto& [name, entry] :
commands_) {
132 if (entry.usage_count > 0) {
133 frequent.push_back(entry);
137 std::sort(frequent.begin(), frequent.end(),
139 return a.usage_count > b.usage_count;
142 if (frequent.size() >
static_cast<size_t>(limit)) {
143 frequent.resize(limit);
std::function< void()> callback