Browse Source

[Fix] Increase/decrease hash_key value for tokens depending on is_unlearn

When relearning a message, this script is called twice:

1. With `is_unlearn` true and the old `is_spam` value
2. With `is_unlearn` false and the new `is_spam` value

If `is_unlearn` is true, the code should not increase the value of the hash_key. Decreasing it ensures that it behaves like a fresh learn with the new is_spam value.
pull/4930/head
aduernberger 1 week ago
parent
commit
26f96b81fd
No account linked to committer's email address
1 changed files with 2 additions and 2 deletions
  1. 2
    2
      lualib/redis_scripts/bayes_learn.lua

+ 2
- 2
lualib/redis_scripts/bayes_learn.lua View File

@@ -26,7 +26,7 @@ redis.call('HSET', prefix, 'version', '2') -- new schema
redis.call('HINCRBY', prefix, learned_key, is_unlearn and -1 or 1) -- increase or decrease learned count

for i, token in ipairs(input_tokens) do
redis.call('HINCRBY', token, hash_key, 1)
redis.call('HINCRBY', token, hash_key, is_unlearn and -1 or 1)
if text_tokens then
local tok1 = text_tokens[i * 2 - 1]
local tok2 = text_tokens[i * 2]
@@ -41,4 +41,4 @@ for i, token in ipairs(input_tokens) do
redis.call('ZINCRBY', prefix .. '_z', is_unlearn and -1 or 1, token)
end
end
end
end

Loading…
Cancel
Save