|
7 | 7 | #include <unistd.h> |
8 | 8 |
|
9 | 9 | #include <hyprutils/string/VarList2.hpp> |
| 10 | +#include <hyprutils/string/String.hpp> |
10 | 11 |
|
11 | 12 | using namespace Hyprutils::String; |
12 | 13 |
|
@@ -76,6 +77,7 @@ constexpr float MIN_SALIENT_MATCH = 0.3F; |
76 | 77 | constexpr float MIN_TOKEN_MATCH = 0.15F; |
77 | 78 | constexpr float POPULARITY_FACTOR = 0.08F; |
78 | 79 | constexpr float NO_SALIENT_PENALTY = 0.01F; |
| 80 | +constexpr float EXACT_MATCH_SCORE = 2.0F; |
79 | 81 |
|
80 | 82 | // |
81 | 83 | static float tokenBestMatch(std::string_view qt, std::string_view lastQ, const std::unordered_set<std::string_view>& cset, const std::vector<std::string_view>& cTok) { |
@@ -115,6 +117,15 @@ static float tokenBestMatch(std::string_view qt, std::string_view lastQ, const s |
115 | 117 | } |
116 | 118 |
|
117 | 119 | static float scoreCandidate(std::string_view query, std::string_view cand, float freq) { |
| 120 | + const float popFactor = 1.F + (POPULARITY_FACTOR * std::log1p(std::max(0.F, freq))); |
| 121 | + |
| 122 | + // exact matches occupy a reserved band above any achievable fuzzy score, so a popular |
| 123 | + // partial match can never outrank them; popularity only orders matches within a band |
| 124 | + std::string queryLower{query}; |
| 125 | + std::ranges::transform(queryLower, queryLower.begin(), ::tolower); |
| 126 | + if (trim(queryLower) == trim(std::string{cand})) |
| 127 | + return EXACT_MATCH_SCORE + popFactor; |
| 128 | + |
118 | 129 | CVarList2 qTokens(std::string{query}, 0, 's', true, false); |
119 | 130 | CVarList2 cTokens(std::string{cand}, 0, 's', true, false); |
120 | 131 |
|
@@ -168,8 +179,6 @@ static float scoreCandidate(std::string_view query, std::string_view cand, float |
168 | 179 | float lenDiff = float(std::abs(int(query.size()) - int(cand.size()))); |
169 | 180 | float lenFactor = std::exp(-lenDiff / 25.f); |
170 | 181 |
|
171 | | - float popFactor = 1.F + (POPULARITY_FACTOR * std::log1p(std::max(0.F, freq))); |
172 | | - |
173 | 182 | return base * lenFactor * popFactor; |
174 | 183 | } |
175 | 184 |
|
|
0 commit comments