Skip to content

Commit

Permalink
Fix search ordering (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdigital authored Jan 13, 2024
1 parent d999b4c commit 09e6142
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/database/query/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ const queryStringRankField = "query_string_rank"
func OrderByQueryStringRank() Option {
return func(ctx OptionBuilder) (OptionBuilder, error) {
return ctx.OrderBy(clause.OrderByColumn{
Column: clause.Column{Name: queryStringRankField},
Desc: true,
Column: clause.Column{Name: queryStringRankField},
Desc: true,
Reorder: true,
}), nil
}
}
Expand Down
13 changes: 12 additions & 1 deletion internal/database/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,19 @@ func applyJoins(sq SubQuery, joins ...TableJoin) {

func (b optionBuilder) applyPost(sq SubQuery) error {
if len(b.orderBy) > 0 {
orderBy := make([]clause.OrderByColumn, 0, len(b.orderBy))
for _, ob := range b.orderBy {
if ob.Reorder {
orderBy = append([]clause.OrderByColumn{{
Column: ob.Column,
Desc: ob.Desc,
}}, orderBy...)
} else {
orderBy = append(orderBy, ob)
}
}
sq.UnderlyingDB().Statement.AddClause(clause.OrderBy{
Columns: b.orderBy,
Columns: orderBy,
})
}
if b.limit.Valid {
Expand Down

0 comments on commit 09e6142

Please sign in to comment.