Add a route that only searches the full-text index

It returns the results in the same order as received from the index to
preserve the relevance ordering.
This commit is contained in:
Eike Kettner
2020-06-23 23:02:58 +02:00
parent d9f0f05613
commit d5c9923a6d
8 changed files with 178 additions and 45 deletions

View File

@ -173,6 +173,11 @@ trait Conversions {
ItemLightList(gs)
}
def mkItemListWithTagsFtsPlain(v: Vector[OFulltext.FtsItemWithTags]): ItemLightList = {
if (v.isEmpty) ItemLightList(Nil)
else ItemLightList(List(ItemLightGroup("Results", v.map(mkItemLightWithTags).toList)))
}
def mkItemLight(i: OItemSearch.ListItem): ItemLight =
ItemLight(
i.id,

View File

@ -83,6 +83,26 @@ object ItemRoutes {
}
} yield resp
case req @ POST -> Root / "searchIndex" =>
for {
mask <- req.as[ItemFtsSearch]
resp <- mask.query match {
case q if q.length > 1 =>
val ftsIn = OFulltext.FtsInput(q)
for {
items <- backend.fulltext.findIndexOnly(
ftsIn,
user.account.collective,
Batch(mask.offset, mask.limit).restrictLimitTo(cfg.maxItemPageSize)
)
ok <- Ok(Conversions.mkItemListWithTagsFtsPlain(items))
} yield ok
case _ =>
BadRequest(BasicResult(false, "Query string too short"))
}
} yield resp
case GET -> Root / Ident(id) =>
for {
item <- backend.itemSearch.findItem(id, user.account.collective)