find only the last version of article on listing

This commit is contained in:
2019-09-06 02:20:35 +02:00
parent 56ea1507f7
commit 05c28a2f62

View File

@@ -9,7 +9,7 @@ create or replace function find_articles(
) language plpgsql as ) language plpgsql as
$$ $$
begin begin
select json_agg(t), (select count(id) from article a where _search is null or _search = '' or a ==> dsl.multi_match('{title^3, content, description}', _search)) select json_agg(t), (select count(id) from article a where (_search is null or _search = '' or a ==> dsl.multi_match('{title^3, content, description}', _search)) and a.is_last_version = true)
into resource, total into resource, total
from ( from (
select select
@@ -17,7 +17,11 @@ begin
find_citizen_by_id(a.created_by_id) as created_by, find_citizen_by_id(a.created_by_id) as created_by,
zdb.score(a.ctid) _score zdb.score(a.ctid) _score
from article as a from article as a
where _search is null or _search = '' or a ==> dsl.multi_match('{title^3, content, description}', _search) where (
_search is null
or _search = ''
or a ==> dsl.multi_match('{title^3, content, description}', _search)
) and a.is_last_version = true
order by order by
_score desc, _score desc,
case direction when 'asc' then case direction when 'asc' then