aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/backends/redis_backend.c1
-rw-r--r--src/libstat/classifiers/bayes.c27
2 files changed, 17 insertions, 11 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index a83ab3081..240584a51 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -609,6 +609,7 @@ rspamd_redis_init (struct rspamd_stat_ctx *ctx,
backend->timeout = REDIS_DEFAULT_TIMEOUT;
}
+ stf->clcf->flags |= RSPAMD_FLAG_CLASSIFIER_INCREMENTING_BACKEND;
return (gpointer)backend;
}
diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c
index 694898db5..3204efc16 100644
--- a/src/libstat/classifiers/bayes.c
+++ b/src/libstat/classifiers/bayes.c
@@ -311,10 +311,13 @@ bayes_learn_spam (struct rspamd_classifier * ctx,
gint id;
struct rspamd_statfile *st;
rspamd_token_t *tok;
+ gboolean incrementing;
g_assert (ctx != NULL);
g_assert (tokens != NULL);
+ incrementing = ctx->cfg->flags & RSPAMD_FLAG_CLASSIFIER_INCREMENTING_BACKEND;
+
for (i = 0; i < tokens->len; i++) {
tok = g_ptr_array_index (tokens, i);
@@ -323,24 +326,26 @@ bayes_learn_spam (struct rspamd_classifier * ctx,
st = g_ptr_array_index (ctx->ctx->statfiles, id);
g_assert (st != NULL);
- if (is_spam) {
- if (st->stcf->is_spam) {
- tok->values[id]++;
+ if (!!st->stcf->is_spam == !!is_spam) {
+ if (incrementing) {
+ tok->values[id] = 1;
}
- else if (tok->values[id] > 0 && unlearn) {
- /* Unlearning */
- tok->values[id]--;
+ else {
+ tok->values[id]++;
}
}
- else {
- if (!st->stcf->is_spam) {
- tok->values[id]++;
+ else if (tok->values[id] > 0 && unlearn) {
+ /* Unlearning */
+ if (incrementing) {
+ tok->values[id] = -1;
}
- else if (tok->values[id] > 0 && unlearn) {
- /* Unlearning */
+ else {
tok->values[id]--;
}
}
+ else if (incrementing) {
+ tok->values[id] = 0;
+ }
}
}