]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Implement per-user ANN support
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Aug 2017 07:17:50 +0000 (08:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Aug 2017 07:17:50 +0000 (08:17 +0100)
src/plugins/lua/fann_redis.lua

index 2ae9c19d84b20599ac848c3715199be16d52530b..6a7a73cdd1d0817c4d1c291c640e89d152e6e37f 100644 (file)
@@ -35,6 +35,7 @@ local default_options = {
     max_epoch = 1000,
     max_usages = 10,
     use_settings = false,
+    per_user = false,
     watch_interval = 60.0,
     mse = 0.001,
     autotrain = true,
@@ -336,6 +337,10 @@ local function fann_scores_filter(task)
       id = rule.prefix .. tostring(sid)
      end
     end
+    if rule.per_user then
+      local r = task:get_principal_recipient()
+      id = id .. r
+    end
 
     if fanns[id].fann then
       local fann_data = task:get_symbols_tokens()
@@ -881,14 +886,17 @@ end
 
 local function ann_push_vector(task)
   local scores = task:get_metric_score()
-  local sid = task:get_settings_id()
 
   for _,rule in ipairs(settings.rules) do
+    local sid = "0"
     if rule.use_settings then
-      fann_train_callback(rule, task, scores[1], scores[2], tostring(sid))
-    else
-      fann_train_callback(rule, task, scores[1], scores[2], "0")
+      sid = tostring(task:get_settings_id())
+    end
+    if rule.per_user then
+      local r = task:get_principal_recipient()
+      sid = sid .. r
     end
+    fann_train_callback(rule, task, scores[1], scores[2], sid)
   end
 end