af_psql_trgm: add support for querying against mariadb FULLTEXT indexes
This commit is contained in:
parent
7e36f6e4c4
commit
9428e2c571
|
@ -23,8 +23,6 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
$enable_globally = checkbox_to_sql_bool($_POST["enable_globally"] ?? "");
|
$enable_globally = checkbox_to_sql_bool($_POST["enable_globally"] ?? "");
|
||||||
|
|
||||||
if ($similarity < 0) $similarity = 0;
|
if ($similarity < 0) $similarity = 0;
|
||||||
if ($similarity > 1) $similarity = 1;
|
|
||||||
|
|
||||||
if ($min_title_length < 0) $min_title_length = 0;
|
if ($min_title_length < 0) $min_title_length = 0;
|
||||||
|
|
||||||
$similarity = sprintf("%.2f", $similarity);
|
$similarity = sprintf("%.2f", $similarity);
|
||||||
|
@ -65,24 +63,43 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
|
|
||||||
print "<p>$title</p>";
|
print "<p>$title</p>";
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id,
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
feed_id,
|
$sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id,
|
||||||
ttrss_entries.title AS title,
|
feed_id,
|
||||||
updated, link,
|
ttrss_entries.title AS title,
|
||||||
ttrss_feeds.title AS feed_title,
|
updated, link,
|
||||||
SIMILARITY(ttrss_entries.title, ?) AS sm
|
ttrss_feeds.title AS feed_title,
|
||||||
FROM
|
SIMILARITY(ttrss_entries.title, :title) AS sm
|
||||||
ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id)
|
FROM
|
||||||
WHERE
|
ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id)
|
||||||
ttrss_entries.id = ref_id AND
|
WHERE
|
||||||
ttrss_user_entries.owner_uid = ? AND
|
ttrss_entries.id = ref_id AND
|
||||||
ttrss_entries.id != ? AND
|
ttrss_user_entries.owner_uid = :owner_uid AND
|
||||||
date_entered >= NOW() - INTERVAL '2 weeks'
|
ttrss_entries.id != :id AND
|
||||||
ORDER BY
|
date_entered >= NOW() - INTERVAL '2 weeks'
|
||||||
sm DESC, date_entered DESC
|
ORDER BY
|
||||||
LIMIT 10");
|
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 "<ul class='panel panel-scrollable'>";
|
print "<ul class='panel panel-scrollable'>";
|
||||||
|
|
||||||
|
@ -140,9 +157,7 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
title="<i class='material-icons'>extension</i> <?= __('Mark similar articles as read (af_psql_trgm)') ?>">
|
title="<i class='material-icons'>extension</i> <?= __('Mark similar articles as read (af_psql_trgm)') ?>">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (Config::get(Config::DB_TYPE) != "pgsql") {
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
print_error("Database type not supported.");
|
|
||||||
} else {
|
|
||||||
$res = $this->pdo->query("select 'similarity'::regproc");
|
$res = $this->pdo->query("select 'similarity'::regproc");
|
||||||
|
|
||||||
if (!$res || !$res->fetch()) {
|
if (!$res || !$res->fetch()) {
|
||||||
|
@ -175,7 +190,11 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
name="similarity" value="<?= htmlspecialchars($similarity) ?>">
|
name="similarity" value="<?= htmlspecialchars($similarity) ?>">
|
||||||
|
|
||||||
<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>
|
<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>
|
||||||
<?= __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") ?>
|
<?php if (Config::get(Config::DB_TYPE) == "pgsql") { ?>
|
||||||
|
<?= __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") ?>
|
||||||
|
<?php } else { ?>
|
||||||
|
<?= __("Setting this value too low might produce false positives, zero disables checking.") ?>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
@ -264,10 +283,10 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
|
|
||||||
function hook_article_filter($article) {
|
function hook_article_filter($article) {
|
||||||
|
|
||||||
if (Config::get(Config::DB_TYPE) != "pgsql") return $article;
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
|
$res = $this->pdo->query("select 'similarity'::regproc");
|
||||||
$res = $this->pdo->query("select 'similarity'::regproc");
|
if (!$res || !$res->fetch()) return $article;
|
||||||
if (!$res || !$res->fetch()) return $article;
|
}
|
||||||
|
|
||||||
$enable_globally = $this->host->get($this, "enable_globally");
|
$enable_globally = $this->host->get($this, "enable_globally");
|
||||||
|
|
||||||
|
@ -317,12 +336,23 @@ class Af_Psql_Trgm extends Plugin {
|
||||||
return $article;
|
return $article;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, ?)) AS ms
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND
|
$sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms
|
||||||
date_entered >= NOW() - interval '1 day' AND
|
FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND
|
||||||
guid != ? AND
|
date_entered >= NOW() - interval '1 day' AND
|
||||||
owner_uid = ?");
|
guid != :guid AND
|
||||||
$sth->execute([$title_escaped, $entry_guid, $owner_uid]);
|
owner_uid = :uid");
|
||||||
|
} else {
|
||||||
|
$sth = $this->pdo->prepare("SELECT MATCH(title) AGAINST (:title) AS ms
|
||||||
|
FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND
|
||||||
|
date_entered >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND
|
||||||
|
guid != :guid AND
|
||||||
|
owner_uid = :uid
|
||||||
|
ORDER BY ms DESC
|
||||||
|
LIMIT 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
$sth->execute(['title' => $title_escaped, 'guid' => $entry_guid, 'uid' => $owner_uid]);
|
||||||
|
|
||||||
$row = $sth->fetch();
|
$row = $sth->fetch();
|
||||||
$similarity_result = $row['ms'];
|
$similarity_result = $row['ms'];
|
||||||
|
|
Loading…
Reference in New Issue