aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sergei O. Udalov <sergei.udalov@gmail.com> 2020-07-01 06:50:34 +0300
committerGravatar GitHub <noreply@github.com> 2020-06-30 20:50:34 -0700
commitc0e407e15670ef143174bffbb105822d9ce2c851 (patch)
tree7ccdaf41e064eecff0e65f751edd143e08e9904e
parentd2f4ed93df5e1866c5389aa2a687a6bc3c944b1d (diff)
downloadv2-c0e407e15670ef143174bffbb105822d9ce2c851.tar.gz
v2-c0e407e15670ef143174bffbb105822d9ce2c851.tar.zst
v2-c0e407e15670ef143174bffbb105822d9ce2c851.zip
Display recent entries first in search results
Diffstat (limited to '')
-rw-r--r--storage/entry_query_builder.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/storage/entry_query_builder.go b/storage/entry_query_builder.go
index 8488af1c..891a4d2e 100644
--- a/storage/entry_query_builder.go
+++ b/storage/entry_query_builder.go
@@ -32,7 +32,9 @@ func (e *EntryQueryBuilder) WithSearchQuery(query string) *EntryQueryBuilder {
nArgs := len(e.args) + 1
e.conditions = append(e.conditions, fmt.Sprintf("e.document_vectors @@ plainto_tsquery($%d)", nArgs))
e.args = append(e.args, query)
- e.WithOrder(fmt.Sprintf("ts_rank(document_vectors, plainto_tsquery($%d))", nArgs))
+
+ // 0.0000001 = 0.1 / (seconds_in_a_day)
+ e.WithOrder(fmt.Sprintf("ts_rank(document_vectors, plainto_tsquery($%d)) - extract (epoch from now() - published_at)::float * 0.0000001", nArgs))
e.WithDirection("DESC")
}
return e