Skip to content

Commit

Permalink
child sorting...
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Aug 27, 2020
1 parent 322c686 commit 7de4f70
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions inst/dbfunctions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,20 @@ AS $func$
DECLARE limitint bigint := cast ( _limit as bigint);
DECLARE pageint bigint := cast ( _page as bigint);
BEGIN
RAISE NOTICE USING MESSAGE = _orderby;
/* set up the secondary language */
IF _lang = 'de' THEN _lang2 = 'en'; ELSE _lang2 = 'de'; END IF;
DROP TABLE IF EXISTS child_ids;
CREATE TEMP TABLE child_ids AS(
CASE WHEN _orderby = 'asc' then
CREATE TEMP TABLE child_ids AS(
WITH ids AS (
select
r.id,
r.id,
COALESCE(
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop and mv.lang = _lang limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop and mv.lang = _lang2 limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop limit 1)
) ordervalue,
/* handle the language for title */
COALESCE(
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle' and mv.lang = _lang limit 1),
Expand All @@ -328,23 +335,54 @@ DROP TABLE IF EXISTS child_ids;
(select mv.value from relations as r2 left join metadata_view as mv on r2.target_id = mv.id where r.id = r2.id and r2.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasAccessRestriction' and
mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle' and mv.lang = _lang) as accessres,
(select mv.value from metadata_view as mv where r.id = mv.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitleImage' limit 1) as titleimage,
(select mv.value from metadata_view as mv where r.id = mv.id and mv.property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' and mv.value like '%vocabs.%' limit 1) as acdhtype,
COALESCE(
(select mv.value from metadata_view as mv where r.id = mv.id and mv.property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' and mv.value like '%vocabs.%' limit 1) as acdhtype
from relations as r
left join identifiers as i on i.id = r.target_id
where r.property = ANY (_rdftype)
and i.ids = _parentid
order by
ordervalue asc
limit limitint
offset pageint
) select * from ids
);

ELSE
CREATE TEMP TABLE child_ids AS(
WITH ids AS (
select
r.id,
COALESCE(
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop and mv.lang = _lang limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop and mv.lang = _lang2 limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = _orderprop limit 1)
) ordervalue
) ordervalue,
/* handle the language for title */
COALESCE(
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle' and mv.lang = _lang limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle' and mv.lang = _lang2 limit 1)
) as title,
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasAvailableDate' limit 1) as avdate,
/* handle the language for the description */
COALESCE(
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasDescription' and mv.lang = _lang limit 1),
(select mv.value from metadata_view as mv where mv.id = r.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasDescription' and mv.lang = _lang2 limit 1)
) description,
(select mv.value from relations as r2 left join metadata_view as mv on r2.target_id = mv.id where r.id = r2.id and r2.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasAccessRestriction' and
mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle' and mv.lang = _lang) as accessres,
(select mv.value from metadata_view as mv where r.id = mv.id and mv.property = 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitleImage' limit 1) as titleimage,
(select mv.value from metadata_view as mv where r.id = mv.id and mv.property = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' and mv.value like '%vocabs.%' limit 1) as acdhtype
from relations as r
left join identifiers as i on i.id = r.target_id
where r.property = ANY (_rdftype)
and i.ids = _parentid
order by
(CASE WHEN _orderby = 'asc' THEN ordervalue END) ASC,
ordervalue DESC
order by
ordervalue desc
limit limitint
offset pageint
) select * from ids
);
END CASE;
alter table child_ids add orderid serial;

RETURN QUERY
Expand Down

0 comments on commit 7de4f70

Please sign in to comment.