From 9428e2c571a38aed36537d072858d245907341e7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 19 Jun 2022 21:36:33 +0300 Subject: [PATCH] af_psql_trgm: add support for querying against mariadb FULLTEXT indexes --- plugins/af_psql_trgm/init.php | 96 +++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index d12f50713..09a9fcd27 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -23,8 +23,6 @@ class Af_Psql_Trgm extends Plugin { $enable_globally = checkbox_to_sql_bool($_POST["enable_globally"] ?? ""); if ($similarity < 0) $similarity = 0; - if ($similarity > 1) $similarity = 1; - if ($min_title_length < 0) $min_title_length = 0; $similarity = sprintf("%.2f", $similarity); @@ -65,24 +63,43 @@ class Af_Psql_Trgm extends Plugin { print "

$title

"; - $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, - feed_id, - ttrss_entries.title AS title, - updated, link, - ttrss_feeds.title AS feed_title, - SIMILARITY(ttrss_entries.title, ?) AS sm - FROM - ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) - WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = ? AND - ttrss_entries.id != ? AND - date_entered >= NOW() - INTERVAL '2 weeks' - ORDER BY - sm DESC, date_entered DESC - LIMIT 10"); + if (Config::get(Config::DB_TYPE) == "pgsql") { + $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, + feed_id, + ttrss_entries.title AS title, + updated, link, + ttrss_feeds.title AS feed_title, + SIMILARITY(ttrss_entries.title, :title) AS sm + FROM + ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) + WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.owner_uid = :owner_uid AND + ttrss_entries.id != :id AND + date_entered >= NOW() - INTERVAL '2 weeks' + ORDER BY + sm DESC, date_entered DESC + LIMIT 10"); + } else { + $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, + feed_id, + ttrss_entries.title AS title, + updated, link, + ttrss_feeds.title AS feed_title, + MATCH (ttrss_entries.title) AGAINST (:title) AS sm + FROM + ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) + WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.owner_uid = :owner_uid AND + ttrss_entries.id != :id AND + date_entered >= DATE_SUB(NOW(), INTERVAL 2 WEEK) + ORDER BY + sm DESC, date_entered DESC + LIMIT 10"); + } - $sth->execute([$title, $owner_uid, $id]); + $sth->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]); print "