Add folder counts to search summary

This commit is contained in:
Eike Kettner 2020-12-16 01:14:27 +01:00
parent a995ea8729
commit 8fba637ebe
5 changed files with 61 additions and 6 deletions

View File

@ -4174,6 +4174,7 @@ components:
- count
- tagCloud
- fieldStats
- folderStats
properties:
count:
type: integer
@ -4184,6 +4185,10 @@ components:
type: array
items:
$ref: "#/components/schemas/FieldStats"
folderStats:
type: array
items:
$ref: "#/components/schemas/FolderStats"
ItemInsights:
description: |
Information about the items in docspell.
@ -4204,6 +4209,25 @@ components:
format: int64
tagCloud:
$ref: "#/components/schemas/TagCloud"
FolderStats:
description: |
Count of folder usage.
required:
- id
- name
- owner
- count
properties:
id:
type: string
format: ident
name:
type: string
owner:
$ref: "#/components/schemas/IdName"
count:
type: integer
format: int32
FieldStats:
description: |
Basic statistics about a custom field.

View File

@ -28,7 +28,15 @@ import org.log4s.Logger
trait Conversions {
def mkSearchStats(sum: OItemSearch.SearchSummary): SearchStats =
SearchStats(sum.count, mkTagCloud(sum.tags), sum.fields.map(mkFieldStats))
SearchStats(
sum.count,
mkTagCloud(sum.tags),
sum.fields.map(mkFieldStats),
sum.folders.map(mkFolderStats)
)
def mkFolderStats(fs: docspell.store.queries.FolderCount): FolderStats =
FolderStats(fs.id, fs.name, mkIdName(fs.owner), fs.count)
def mkFieldStats(fs: docspell.store.queries.FieldStats): FieldStats =
FieldStats(

View File

@ -0,0 +1,5 @@
package docspell.store.queries
import docspell.common._
case class FolderCount(id: Ident, name: String, owner: IdRef, count: Int)

View File

@ -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)

View File

@ -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]
)