Skip to content

Commit

Permalink
Search bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainer Simon committed Sep 12, 2019
1 parent 810e3a2 commit 03a3172
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions app/services/document/search/SearchOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,40 @@ trait SearchOps { self: DocumentService =>
"""
SELECT
document.*,
cloned_from.owner AS cloned_from_user,
has_clones,
file_count,
content_types
FROM document
LEFT JOIN (
LEFT OUTER JOIN document cloned_from
ON cloned_from.id = document.cloned_from
LEFT JOIN (
SELECT
count(*) AS file_count,
array_agg(DISTINCT content_type) AS content_types,
document_id
FROM document_filepart
GROUP BY document_id
) AS parts ON parts.document_id = document.id
LEFT OUTER JOIN (
WITH RECURSIVE descendants AS (
SELECT
count(*) AS file_count,
array_agg(DISTINCT content_type) AS content_types,
document_id
FROM document_filepart
GROUP BY document_id
) AS parts ON parts.document_id = document.id
document.cloned_from AS root_id,
document.id,
document.cloned_from
FROM document WHERE document.cloned_from IS NOT NULL
UNION ALL
SELECT parent.root_id, doc.id, doc.cloned_from
FROM document doc
JOIN descendants parent
ON doc.cloned_from = parent.id
)
SELECT
root_id,
count(*) AS has_clones
FROM descendants
GROUP BY root_id
) AS clones ON clones.root_id = document.id
"""

val buildQuery =
Expand Down

0 comments on commit 03a3172

Please sign in to comment.