Skip to content
Snippets Groups Projects
Verified Commit 0a1d5a44 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Unify ranking parameters

parent 1f47e8b2
No related branches found
No related tags found
No related merge requests found
Pipeline #795 passed
......@@ -69,15 +69,15 @@ class Database
private function apply_config(\PDOStatement $stmt)
{
if ($this->enable_ranking) {
if (!($this->backend instanceof SQLiteSmartBackend)) {
$stmt->bindValue(':config_normalization', 4, PDO::PARAM_INT);
}
$stmt->bindValue(':weight_content', 14, PDO::PARAM_INT);
$values = [
":config_normalizatio" => 4,
":weight_content" => 4,
":weight_type" => 5,
":weight_time" => 1,
];
foreach ($this->rankingParameters() as $parameter) {
$stmt->bindValue($parameter, $values[$parameter], PDO::PARAM_INT);
}
$stmt->bindValue(':weight_type', 32, PDO::PARAM_INT);
$stmt->bindValue(':weight_time', 1, PDO::PARAM_INT);
}
public function find(string $query, string $since = null, string $before = null, string $buffer = null, string $network = null, string $sender = null, int $limitPerBuffer = 4): array
......
......@@ -4,6 +4,8 @@ namespace QuasselRestSearch;
interface Backend
{
function rankingParameters(): array;
public function findUser(): \PDOStatement;
public function findInBuffers(): \PDOStatement;
......@@ -17,4 +19,4 @@ interface Backend
public function loadAfter(): \PDOStatement;
public function loadBefore(): \PDOStatement;
}
\ No newline at end of file
}
......@@ -33,18 +33,28 @@ class PostgresSmartBackend implements Backend
return array_key_exists('tsqueryfunction', $this->options) ? $this->options['tsqueryfunction'] : "plainto_tsquery('english', :query)";
}
function rankingParameters(): array
{
return [
":config_normalization",
":weight_content",
":weight_type",
":weight_time"
];
}
private function rankingFunction(): string
{
if ($this->enable_ranking) {
return "(
(ts_rank_cd(tsv, query, :config_normalization) ^ :weight_content) *
(ts_rank_cd(tsv, query, :config_normalization) ^ (2 ^ :weight_content)) *
((CASE
WHEN TYPE IN (1, 4) THEN 1.0
WHEN TYPE IN (2, 1024, 2048, 4096, 16384) THEN 0.8
WHEN TYPE IN (32, 64, 128, 256, 512, 32768, 65536) THEN 0.6
WHEN TYPE IN (8, 16, 8192, 131072) THEN 0.4
ELSE 0.2 END) ^ :weight_type) *
((1 / (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) - EXTRACT(EPOCH FROM time))) ^ :weight_time)
ELSE 0.2 END) ^ (2 ^ :weight_type)) *
((1 / (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) - EXTRACT(EPOCH FROM time))) ^ (2 ^ :weight_time))
)";
} else {
return "(
......@@ -53,8 +63,8 @@ class PostgresSmartBackend implements Backend
WHEN TYPE IN (2, 1024, 2048, 4096, 16384) THEN 0.8
WHEN TYPE IN (32, 64, 128, 256, 512, 32768, 65536) THEN 0.6
WHEN TYPE IN (8, 16, 8192, 131072) THEN 0.4
ELSE 0.2 END) ^ :weight_type) *
((1 / (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) - EXTRACT(EPOCH FROM time))) ^ :weight_time)
ELSE 0.2 END) ^ (2 ^ :weight_type)) *
((1 / (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) - EXTRACT(EPOCH FROM time))) ^ (2 ^ :weight_time))
)";
}
}
......
......@@ -124,6 +124,15 @@ class SQLiteSmartBackend implements Backend
");
}
function rankingParameters(): array
{
return [
":weight_content",
":weight_type",
":weight_time"
];
}
private function rankingFunction(): string
{
// TODO: Properly port missing support of Pow in sqlite
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment