]> git.wh0rd.org Git - tt-rss.git/commitdiff
af_psql_trgm: match equal strings correctly, remove score checking from show related...
authorAndrew Dolgov <noreply@fakecake.org>
Tue, 23 Jun 2015 01:35:24 +0000 (18:35 -0700)
committerAndrew Dolgov <noreply@fakecake.org>
Tue, 23 Jun 2015 01:35:24 +0000 (18:35 -0700)
plugins/af_psql_trgm/init.php

index aebe3d082983fb36247a76c1b96426d8a6abd717..f41455f832ae63b49d5be43d41ed2d2bbf06ba7c 100644 (file)
@@ -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"]))
                                . "</div>";
 
-                       print "<img src='images/score_high.png' title='".sprintf("%.2f", $line['sm'])."'
+                       $sm = sprintf("%.2f", $line['sm']);
+                       print "<img src='images/score_high.png' title='$sm'
                                style='vertical-align : middle'>";
 
                        $article_link = htmlspecialchars($line["link"]);
@@ -89,6 +89,8 @@ class Af_Psql_Trgm extends Plugin {
                        print " (<a href=\"#\" onclick=\"viewfeed(".$line["feed_id"].")\">".
                                htmlspecialchars($line["feed_title"])."</a>)";
 
+                       print " <span class='insensitive'>($sm)</span>";
+
                        print "</li>";
                }
 
@@ -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;