Can sort by vote and popularity

This commit is contained in:
2019-10-16 16:28:23 +02:00
parent 32417d3276
commit 846b23b550
2 changed files with 19 additions and 2 deletions

View File

@@ -23,12 +23,14 @@ begin
or _search = ''
or a ==> dsl.multi_match('{title^3, content, description, tags}', _search)
) and a.last_version = true
order by
_score desc,
case direction when 'asc' then
case sort
when 'title' then a.title
when 'created_at' then a.created_at::text
when 'vote' then count_vote(a.id)->>'score'
when 'popularity' then count_vote(a.id)->>'total'
else null
end
end,
@@ -36,6 +38,8 @@ begin
case sort
when 'title' then a.title
when 'created_at' then a.created_at::text
when 'vote' then count_vote(a.id)->>'score'
when 'popularity' then count_vote(a.id)->>'total'
end
end
desc,