Add a route to get search summary

This commit is contained in:
Eike Kettner 2020-12-15 23:33:03 +01:00
parent 77627534bc
commit 80e23d1c84
3 changed files with 107 additions and 0 deletions

View File

@ -1375,6 +1375,27 @@ paths:
schema:
$ref: "#/components/schemas/ItemLightList"
/sec/item/searchStats:
post:
tags: [ Item ]
summary: Get basic statistics about the data of a search.
description: |
Takes a search query and returns a summary about the results.
security:
- authTokenHeader: []
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ItemSearch"
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/SearchStats"
/sec/item/{id}:
get:
tags: [ Item ]
@ -4146,6 +4167,23 @@ components:
key:
type: string
format: ident
SearchStats:
description: |
A summary of search results.
required:
- count
- tagCloud
- fieldStats
properties:
count:
type: integer
format: int32
tagCloud:
$ref: "#/components/schemas/TagCloud"
fieldStats:
type: array
items:
$ref: "#/components/schemas/FieldStats"
ItemInsights:
description: |
Information about the items in docspell.
@ -4166,6 +4204,51 @@ components:
format: int64
tagCloud:
$ref: "#/components/schemas/TagCloud"
FieldStats:
description: |
Basic statistics about a custom field.
required:
- id
- name
- ftype
- count
- avg
- sum
- max
- min
properties:
id:
type: string
format: ident
name:
type: string
format: ident
label:
type: string
ftype:
type: string
format: customfieldtype
enum:
- text
- numeric
- date
- bool
- money
count:
type: integer
format: int32
sum:
type: number
format: double
avg:
type: number
format: double
max:
type: number
format: double
min:
type: number
format: double
TagCloud:
description: |
A tag "cloud"

View File

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

View File

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