summaryrefslogtreecommitdiff
path: root/lua/telescope/sorters.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/telescope/sorters.lua')
-rw-r--r--lua/telescope/sorters.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua
index a648007..c97a1a9 100644
--- a/lua/telescope/sorters.lua
+++ b/lua/telescope/sorters.lua
@@ -1,3 +1,5 @@
+local util = require('telescope.utils')
+
local sorters = {}
@@ -31,4 +33,30 @@ end
sorters.Sorter = Sorter
+sorters.get_ngram_sorter = function()
+ return Sorter:new {
+ scoring_function = function(_, prompt, line)
+ if prompt == "" or prompt == nil then
+ return 1
+ end
+
+ local ok, result = pcall(function()
+ local ngram = util.new_ngram { N = 4 }
+ ngram:add(line)
+
+ local score = ngram:score(prompt)
+ if score == 0 then
+ return -1
+ end
+
+ -- return math.pow(math.max(score, 0.0001), -1)
+ return score
+ end)
+
+ print(prompt, line, result)
+ return ok and result or 1
+ end
+ }
+end
+
return sorters