From 5df13f31ef5642e583d9fb8755bd3ed78e16f594 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Jun 2015 10:56:42 +0300 Subject: [PATCH] bayes: fix check for already categorized articles --- plugins/af_sort_bayes/init.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/af_sort_bayes/init.php b/plugins/af_sort_bayes/init.php index d2e659cae..0bdfafa17 100644 --- a/plugins/af_sort_bayes/init.php +++ b/plugins/af_sort_bayes/init.php @@ -263,13 +263,18 @@ class Af_Sort_Bayes extends Plugin { function hook_article_filter($article) { $owner_uid = $article["owner_uid"]; + // guid already includes owner_uid so we don't need to include it + $result = $this->dbh->query("SELECT id FROM {$this->sql_prefix}_references WHERE + document_id = '" . $this->dbh->escape_string($article['guid_hashed']) . "'"); + + if (db_num_rows($result) != 0) { + _debug("bayes: article already categorized"); + return $article; + } + $nbs = new NaiveBayesianStorage($owner_uid); $nb = new NaiveBayesianNgram($nbs, 3); - $ref = $nbs->getReference($article["guid"], false); - - if (isset($ref["category_id"])) return $article; // already categorized - $categories = $nbs->getCategories(); if (count($categories) > 0) {