mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-30 21:40:12 +00:00 
			
		
		
		
	Get basic search summary
This commit is contained in:
		| @@ -66,8 +66,8 @@ trait OCollective[F[_]] { | ||||
|  | ||||
| object OCollective { | ||||
|  | ||||
|   type TagCount = QCollective.TagCount | ||||
|   val TagCount = QCollective.TagCount | ||||
|   type TagCount = docspell.store.queries.TagCount | ||||
|   val TagCount = docspell.store.queries.TagCount | ||||
|  | ||||
|   type InsightData = QCollective.InsightData | ||||
|   val insightData = QCollective.InsightData | ||||
|   | ||||
| @@ -24,6 +24,8 @@ trait OItemSearch[F[_]] { | ||||
|       maxNoteLen: Int | ||||
|   )(q: Query, batch: Batch): F[Vector[ListItemWithTags]] | ||||
|  | ||||
|   def findItemsSummary(q: Query): F[SearchSummary] | ||||
|  | ||||
|   def findAttachment(id: Ident, collective: Ident): F[Option[AttachmentData[F]]] | ||||
|  | ||||
|   def findAttachmentSource( | ||||
| @@ -53,6 +55,9 @@ trait OItemSearch[F[_]] { | ||||
|  | ||||
| object OItemSearch { | ||||
|  | ||||
|   type SearchSummary = queries.SearchSummary | ||||
|   val SearchSummary = queries.SearchSummary | ||||
|  | ||||
|   type CustomValue = queries.CustomValue | ||||
|   val CustomValue = queries.CustomValue | ||||
|  | ||||
| @@ -139,6 +144,12 @@ object OItemSearch { | ||||
|           .toVector | ||||
|       } | ||||
|  | ||||
|       def findItemsSummary(q: Query): F[SearchSummary] = | ||||
|         for { | ||||
|           tags  <- store.transact(QItem.searchTagSummary(q)) | ||||
|           count <- store.transact(QItem.searchCountSummary(q)) | ||||
|         } yield SearchSummary(count, tags) | ||||
|  | ||||
|       def findAttachment(id: Ident, collective: Ident): F[Option[AttachmentData[F]]] = | ||||
|         store | ||||
|           .transact(RAttachment.findByIdAndCollective(id, collective)) | ||||
|   | ||||
| @@ -33,8 +33,6 @@ object QCollective { | ||||
|     } yield Names(orgs.map(_.name), pers.map(_.name), equp.map(_.name))) | ||||
|       .getOrElse(Names.empty) | ||||
|  | ||||
|   case class TagCount(tag: RTag, count: Int) | ||||
|  | ||||
|   case class InsightData( | ||||
|       incoming: Int, | ||||
|       outgoing: Int, | ||||
|   | ||||
| @@ -234,6 +234,30 @@ object QItem { | ||||
|     sql.query[ListItem].stream | ||||
|   } | ||||
|  | ||||
|   def searchTagSummary(q: Query): ConnectionIO[List[TagCount]] = { | ||||
|     val tagFrom = | ||||
|       from(ti) | ||||
|         .innerJoin(tag, tag.tid === ti.tagId) | ||||
|         .innerJoin(i, i.id === ti.itemId) | ||||
|  | ||||
|     findItemsBase(q, 0) | ||||
|       .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] | ||||
|   } | ||||
|  | ||||
|   def searchCountSummary(q: Query): ConnectionIO[Int] = | ||||
|     findItemsBase(q, 0) | ||||
|       .withSelect(Nel.of(count(i.id).as("num"))) | ||||
|       .changeWhere(c => c && queryCondition(q)) | ||||
|       .build | ||||
|       .query[Int] | ||||
|       .unique | ||||
|  | ||||
|   def findSelectedItems( | ||||
|       q: Query, | ||||
|       maxNoteLen: Int, | ||||
|   | ||||
| @@ -0,0 +1,3 @@ | ||||
| package docspell.store.queries | ||||
|  | ||||
| case class SearchSummary(count: Int, tags: List[TagCount]) | ||||
| @@ -0,0 +1,5 @@ | ||||
| package docspell.store.queries | ||||
|  | ||||
| import docspell.store.records.RTag | ||||
|  | ||||
| case class TagCount(tag: RTag, count: Int) | ||||
		Reference in New Issue
	
	Block a user