Skip to content

Commit 733f26f

Browse files
committed
fix: frequency sort
1 parent be9c119 commit 733f26f

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lua/text-transform/telescope.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,26 @@ local frequency_sorter = Sorter:new({
7575
break
7676
end
7777
end
78+
D.log("telescope", "prompt %s line %s", prompt, line)
7879
-- Basic filtering based on prompt matching, non-matching items score below 0 to exclude them
79-
local basic_score = generic_sorter:score(prompt, entry) or 0
80-
-- D.log("telescope", "basic_score: %s", basic_score)
80+
local basic_score = (generic_sorter:scoring_function(prompt, line) or 0)
81+
D.log("telescope", "%s basic_score: %s", entry.value, basic_score)
8182
if basic_score < 0 then
8283
return basic_score
8384
end
8485

8586
-- D.log("telescope", "entry: %s", vim.inspect(entry))
8687
-- D.log("telescope", "prompt: %s", prompt)
8788
-- Calculate score based on frequency, higher frequency should have lower score
88-
local freq_score = (entry.frequency or 1) -- Multiply by -1 because we want higher frequency to have lower score
89+
local freq_score = (entry.frequency or 1) * 10
8990

90-
-- D.log("telescope", "freq_score: %s", freq_score)
91-
D.log("telescope", "%s final_score: %s", line, 99999999 - freq_score * 100 + basic_score)
91+
D.log("telescope", "freq_score: %s", freq_score)
92+
93+
local final_score = 999999999 - freq_score + basic_score
94+
D.log("telescope", "%s final_score: %s", line, final_score)
9295

9396
-- Combine scores, with frequency having the primary influence if present
94-
return 99999999 - freq_score * 100 + basic_score -- Division to ensure frequency has a higher weight
97+
return final_score
9598
end,
9699
})
97100
---@diagnostic disable-next-line: unused-local

0 commit comments

Comments
 (0)