From 4cbca7b28e3be75e24cf8f6e6eac2aa393973aed Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Jun 2015 18:35:24 -0700 Subject: [PATCH] af_psql_trgm: match equal strings correctly, remove score checking from show related because filter plugin does not take it into account --- plugins/af_psql_trgm/init.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index aebe3d082..f41455f83 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -65,7 +65,6 @@ class Af_Psql_Trgm extends Plugin { ttrss_entries.id = ref_id AND ttrss_user_entries.owner_uid = $owner_uid AND ttrss_entries.id != $id AND - score >= 0 AND date_entered >= NOW() - INTERVAL '2 weeks' ORDER BY sm DESC, date_entered DESC @@ -79,7 +78,8 @@ class Af_Psql_Trgm extends Plugin { smart_date_time(strtotime($line["updated"])) . ""; - print ""; $article_link = htmlspecialchars($line["link"]); @@ -89,6 +89,8 @@ class Af_Psql_Trgm extends Plugin { print " (". htmlspecialchars($line["feed_title"]).")"; + print " ($sm)"; + print ""; } @@ -253,19 +255,37 @@ class Af_Psql_Trgm extends Plugin { $min_title_length = (int) $this->host->get($this, "min_length"); if (mb_strlen($article["title"]) < $min_title_length) return $article; + $owner_uid = $article["owner_uid"]; $feed_id = $article["feed"]["id"]; - $title_escaped = db_escape_string($article["title"]); + // trgm does not return similarity=1 for completely equal strings + + $result = db_query("SELECT COUNT(id) AS nequal + FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND + date_entered >= NOW() - interval '1 day' AND + title = '$title_escaped' AND + feed_id != '$feed_id' AND + owner_uid = $owner_uid"); + + $nequal = db_fetch_result($result, 0, "nequal"); + _debug("af_psql_trgm: num equals: $nequal"); + + if ($nequal != 0) { + $article["force_catchup"] = true; + return $article; + } + $result = db_query("SELECT MAX(SIMILARITY(title, '$title_escaped')) AS ms FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND date_entered >= NOW() - interval '1 day' AND + feed_id != '$feed_id' AND owner_uid = $owner_uid"); $similarity_result = db_fetch_result($result, 0, "ms"); - //_debug("similarity result: $similarity_result"); + _debug("af_psql_trgm: similarity result: $similarity_result"); if ($similarity_result >= $similarity) { $article["force_catchup"] = true;