浏览代码

[Project] Add classify redis script

tags/3.8.0
Vsevolod Stakhov 5 个月前
父节点
当前提交
44c6c563c2
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 27 次插入0 次删除
  1. 1
    0
      .luacheckrc
  2. 26
    0
      lualib/redis_scripts/bayes_classify.lua

+ 1
- 0
.luacheckrc 查看文件

@@ -64,6 +64,7 @@ files['/**/lualib/redis_scripts/**'].globals = {
'redis',
'KEYS',
'cjson',
'cmsgpack',
}

files['/**/src/rspamadm/*'].globals = {

+ 26
- 0
lualib/redis_scripts/bayes_classify.lua 查看文件

@@ -0,0 +1,26 @@
-- Lua script to perform bayes classification
-- This script accepts the following parameters:
-- key1 - prefix for bayes tokens (e.g. for per-user classification)
-- key2 - set of tokens encoded in messagepack array of int64_t

local prefix = KEYS[1]
local input_tokens = cmsgpack.unpack(KEYS[2])
local output_spam = {}
local output_ham = {}

for i, token in ipairs(input_tokens) do
local token_data = redis.call('HMGET', prefix .. tostring(token), 'H', 'S')

if token_data then
local ham_count = tonumber(token_data[1]) or 0
local spam_count = tonumber(token_data[2]) or 0

output_ham[i] = ham_count
output_spam[i] = spam_count
else
output_ham[i] = 0
output_spam[i] = 0
end
end

return cmsgpack.pack({ output_ham, output_spam })

正在加载...
取消
保存