summaryrefslogtreecommitdiff
path: root/lua/telescope/sorters.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-08-03 20:40:04 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-08-03 20:40:04 -0400
commit96cac0a8c861d5cdb1bb7765cc2d20e47ebb7885 (patch)
tree43edecaeef53e683cdacc9588c75817d62f7844f /lua/telescope/sorters.lua
parentfa0382d93e73b66e7ec769cec27b9fbb21020641 (diff)
Work on ngram sorter
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