Jelajahi Sumber

Display recent entries first in search results

Sergei O. Udalov 5 tahun lalu
induk
melakukan
c0e407e156
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      storage/entry_query_builder.go

+ 3 - 1
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