Can sort by vote and popularity
This commit is contained in:
@@ -208,7 +208,7 @@ paths:
|
|||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/page'
|
- $ref: '#/components/parameters/page'
|
||||||
- $ref: '#/components/parameters/limit'
|
- $ref: '#/components/parameters/limit'
|
||||||
- $ref: '#/components/parameters/sort'
|
- $ref: '#/components/parameters/articleSort'
|
||||||
- $ref: '#/components/parameters/direction'
|
- $ref: '#/components/parameters/direction'
|
||||||
- $ref: '#/components/parameters/search'
|
- $ref: '#/components/parameters/search'
|
||||||
responses:
|
responses:
|
||||||
@@ -721,6 +721,19 @@ components:
|
|||||||
required: false
|
required: false
|
||||||
schema:
|
schema:
|
||||||
type: string
|
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:
|
direction:
|
||||||
name: direction
|
name: direction
|
||||||
in: query
|
in: query
|
||||||
|
|||||||
@@ -23,12 +23,14 @@ begin
|
|||||||
or _search = ''
|
or _search = ''
|
||||||
or a ==> dsl.multi_match('{title^3, content, description, tags}', _search)
|
or a ==> dsl.multi_match('{title^3, content, description, tags}', _search)
|
||||||
) and a.last_version = true
|
) and a.last_version = true
|
||||||
|
|
||||||
order by
|
order by
|
||||||
_score desc,
|
|
||||||
case direction when 'asc' then
|
case direction when 'asc' then
|
||||||
case sort
|
case sort
|
||||||
when 'title' then a.title
|
when 'title' then a.title
|
||||||
when 'created_at' then a.created_at::text
|
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
|
else null
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -36,6 +38,8 @@ begin
|
|||||||
case sort
|
case sort
|
||||||
when 'title' then a.title
|
when 'title' then a.title
|
||||||
when 'created_at' then a.created_at::text
|
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
|
||||||
end
|
end
|
||||||
desc,
|
desc,
|
||||||
|
|||||||
Reference in New Issue
Block a user