mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 18:38:26 +00:00
Add folder counts to search summary
This commit is contained in:
@ -0,0 +1,5 @@
|
||||
package docspell.store.queries
|
||||
|
||||
import docspell.common._
|
||||
|
||||
case class FolderCount(id: Ident, name: String, owner: IdRef, count: Int)
|
@ -236,10 +236,11 @@ object QItem {
|
||||
|
||||
def searchStats(q: Query): ConnectionIO[SearchSummary] =
|
||||
for {
|
||||
count <- searchCountSummary(q)
|
||||
tags <- searchTagSummary(q)
|
||||
fields <- searchFieldSummary(q)
|
||||
} yield SearchSummary(count, tags, fields)
|
||||
count <- searchCountSummary(q)
|
||||
tags <- searchTagSummary(q)
|
||||
fields <- searchFieldSummary(q)
|
||||
folders <- searchFolderSummary(q)
|
||||
} yield SearchSummary(count, tags, fields, folders)
|
||||
|
||||
def searchTagSummary(q: Query): ConnectionIO[List[TagCount]] = {
|
||||
val tagFrom =
|
||||
@ -265,6 +266,18 @@ object QItem {
|
||||
.query[Int]
|
||||
.unique
|
||||
|
||||
def searchFolderSummary(q: Query): ConnectionIO[List[FolderCount]] = {
|
||||
val fu = RUser.as("fu")
|
||||
findItemsBase(q, 0).unwrap
|
||||
.withSelect(select(f.id, f.name, f.owner, fu.login).append(count(i.id).as("num")))
|
||||
.changeFrom(_.innerJoin(fu, fu.uid === f.owner))
|
||||
.changeWhere(c => c && queryCondition(q))
|
||||
.groupBy(f.id, f.name, f.owner, fu.login)
|
||||
.build
|
||||
.query[FolderCount]
|
||||
.to[List]
|
||||
}
|
||||
|
||||
def searchFieldSummary(q: Query): ConnectionIO[List[FieldStats]] = {
|
||||
val fieldJoin =
|
||||
from(cv)
|
||||
|
@ -1,3 +1,8 @@
|
||||
package docspell.store.queries
|
||||
|
||||
case class SearchSummary(count: Int, tags: List[TagCount], fields: List[FieldStats])
|
||||
case class SearchSummary(
|
||||
count: Int,
|
||||
tags: List[TagCount],
|
||||
fields: List[FieldStats],
|
||||
folders: List[FolderCount]
|
||||
)
|
||||
|
Reference in New Issue
Block a user