mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Add a route to get search summary
This commit is contained in:
@ -27,6 +27,22 @@ import org.log4s.Logger
|
||||
|
||||
trait Conversions {
|
||||
|
||||
def mkSearchStats(sum: OItemSearch.SearchSummary): SearchStats =
|
||||
SearchStats(sum.count, mkTagCloud(sum.tags), sum.fields.map(mkFieldStats))
|
||||
|
||||
def mkFieldStats(fs: docspell.store.queries.FieldStats): FieldStats =
|
||||
FieldStats(
|
||||
fs.field.id,
|
||||
fs.field.name,
|
||||
fs.field.label,
|
||||
fs.field.ftype,
|
||||
fs.count,
|
||||
fs.sum.doubleValue,
|
||||
fs.avg.doubleValue,
|
||||
fs.max.doubleValue,
|
||||
fs.min.doubleValue
|
||||
)
|
||||
|
||||
// insights
|
||||
def mkItemInsights(d: InsightData): ItemInsights =
|
||||
ItemInsights(
|
||||
|
@ -143,6 +143,14 @@ object ItemRoutes {
|
||||
}
|
||||
} yield resp
|
||||
|
||||
case req @ POST -> Root / "searchStats" =>
|
||||
for {
|
||||
mask <- req.as[ItemSearch]
|
||||
query = Conversions.mkQuery(mask, user.account)
|
||||
stats <- backend.itemSearch.findItemsSummary(query)
|
||||
resp <- Ok(Conversions.mkSearchStats(stats))
|
||||
} yield resp
|
||||
|
||||
case GET -> Root / Ident(id) =>
|
||||
for {
|
||||
item <- backend.itemSearch.findItem(id, user.account.collective)
|
||||
|
Reference in New Issue
Block a user