From c1f5815b4b8b668031416f8416d0c1e8fedc47ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C4=85tkowski?= Date: Sun, 7 Aug 2022 22:14:26 +0200 Subject: [PATCH] Improve PostgreSQL serach a little --- pkg/persistence/postgres.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/persistence/postgres.go b/pkg/persistence/postgres.go index c610e9e..82734e4 100644 --- a/pkg/persistence/postgres.go +++ b/pkg/persistence/postgres.go @@ -229,10 +229,15 @@ func (db *postgresDatabase) QueryTorrents( {{ else }} similarity(name, '{{ .Query }}') * -1 {{ end }} -{{GTEorLTE .Ascending}} {{.LastOrderedValue}} - {{ if .QueryExists }} AND {{ end }} + {{GTEorLTE .Ascending}} {{.LastOrderedValue}} + {{ if .QueryExists }} + AND + {{ end }} + {{ end }} + {{ if and .QueryExists .FirstPage }} WHERE {{ end }} + {{ if .QueryExists }} + to_tsvector(replace(replace(name, '.', ' '), '-', ' ')) @@ plainto_tsquery('{{ .Query }}') {{ end }} - {{ if and .QueryExists .FirstPage }} WHERE {{ end }}{{ if .QueryExists }} to_tsvector(replace(name, '.', ' ')) @@ plainto_tsquery('{{ .Query }}') {{ end }} ORDER BY {{.OrderOn}} {{AscOrDesc .Ascending}} LIMIT {{.Limit}}; `, struct {