From: Andrew Dolgov Date: Tue, 23 Jun 2015 01:35:24 +0000 (-0700) Subject: af_psql_trgm: match equal strings correctly, remove score checking from show related... X-Git-Tag: 16.3~272 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=4cbca7b28e3be75e24cf8f6e6eac2aa393973aed;p=tt-rss.git af_psql_trgm: match equal strings correctly, remove score checking from show related because filter plugin does not take it into account --- diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index aebe3d08..f41455f8 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;