mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Return all tags in search stats result
Before only tags with a count > 0 were included. Now those that have not attached to any item are returned as well.
This commit is contained in:
parent
3d164206d3
commit
3fccc3df39
@ -250,14 +250,22 @@ object QItem {
|
||||
.innerJoin(tag, tag.tid === ti.tagId)
|
||||
.innerJoin(i, i.id === ti.itemId)
|
||||
|
||||
findItemsBase(q, 0).unwrap
|
||||
.withSelect(select(tag.all).append(count(i.id).as("num")))
|
||||
.changeFrom(_.prepend(tagFrom))
|
||||
.changeWhere(c => c && queryCondition(q))
|
||||
.groupBy(tag.tid)
|
||||
.build
|
||||
.query[TagCount]
|
||||
.to[List]
|
||||
val tagCloud =
|
||||
findItemsBase(q, 0).unwrap
|
||||
.withSelect(select(tag.all).append(count(i.id).as("num")))
|
||||
.changeFrom(_.prepend(tagFrom))
|
||||
.changeWhere(c => c && queryCondition(q))
|
||||
.groupBy(tag.tid)
|
||||
.build
|
||||
.query[TagCount]
|
||||
.to[List]
|
||||
|
||||
// the previous query starts from tags, so items with tag-count=0
|
||||
// are not included they are fetched separately
|
||||
for {
|
||||
existing <- tagCloud
|
||||
other <- RTag.findOthers(q.account.collective, existing.map(_.tag.tagId))
|
||||
} yield existing ++ other.map(TagCount(_, 0))
|
||||
}
|
||||
|
||||
def searchCountSummary(q: Query): ConnectionIO[Int] =
|
||||
|
@ -135,6 +135,19 @@ object RTag {
|
||||
}
|
||||
}
|
||||
|
||||
def findOthers(coll: Ident, excludeTags: List[Ident]): ConnectionIO[List[RTag]] = {
|
||||
val excl =
|
||||
NonEmptyList
|
||||
.fromList(excludeTags)
|
||||
.map(nel => T.tid.notIn(nel))
|
||||
|
||||
Select(
|
||||
select(T.all),
|
||||
from(T),
|
||||
T.cid === coll &&? excl
|
||||
).orderBy(T.name.asc).build.query[RTag].to[List]
|
||||
}
|
||||
|
||||
def delete(tagId: Ident, coll: Ident): ConnectionIO[Int] =
|
||||
DML.delete(T, T.tid === tagId && T.cid === coll)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user