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

@@ -208,7 +208,7 @@ paths:
parameters:
- $ref: '#/components/parameters/page'
- $ref: '#/components/parameters/limit'
- $ref: '#/components/parameters/sort'
- $ref: '#/components/parameters/articleSort'
- $ref: '#/components/parameters/direction'
- $ref: '#/components/parameters/search'
responses:
@@ -721,6 +721,19 @@ components:
required: false
schema:
type: string
articleSort:
name: sort
in: query
description: The sort field name
example: createdAt
required: false
schema:
type: string
enum:
- title
- createdAt
- vote
- popularity
direction:
name: direction
in: query

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,