diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OSimpleSearch.scala b/modules/backend/src/main/scala/docspell/backend/ops/OSimpleSearch.scala index 34e015b1..9050bb06 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OSimpleSearch.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OSimpleSearch.scala @@ -19,7 +19,10 @@ import docspell.store.queries.SearchSummary import org.log4s.getLogger -/** A "porcelain" api on top of OFulltext and OItemSearch. */ +/** A "porcelain" api on top of OFulltext and OItemSearch. This takes + * care of restricting the items to a subset, e.g. only items that + * have a "valid" state. + */ trait OSimpleSearch[F[_]] { /** Search for items using the given query and optional fulltext @@ -268,17 +271,19 @@ object OSimpleSearch { def searchSummary( useFTS: Boolean - )(q: Query, fulltextQuery: Option[String]): F[SearchSummary] = + )(q: Query, fulltextQuery: Option[String]): F[SearchSummary] = { + val validItemQuery = q.withFix(_.andQuery(ItemQuery.Expr.ValidItemStates)) fulltextQuery match { case Some(ftq) if useFTS => if (q.isEmpty) fts.findIndexOnlySummary(q.fix.account, OFulltext.FtsInput(ftq)) else fts - .findItemsSummary(q, OFulltext.FtsInput(ftq)) + .findItemsSummary(validItemQuery, OFulltext.FtsInput(ftq)) case _ => - is.findItemsSummary(q) + is.findItemsSummary(validItemQuery) } + } } } diff --git a/modules/store/src/main/scala/docspell/store/queries/QCollective.scala b/modules/store/src/main/scala/docspell/store/queries/QCollective.scala index ede76360..daeb380f 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QCollective.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QCollective.scala @@ -73,12 +73,16 @@ object QCollective { val q0 = Select( count(i.id).s, from(i), - i.cid === coll && i.incoming === Direction.incoming + i.cid === coll && i.incoming === Direction.incoming && i.state.in( + ItemState.validStates + ) ).build.query[Int].unique val q1 = Select( count(i.id).s, from(i), - i.cid === coll && i.incoming === Direction.outgoing + i.cid === coll && i.incoming === Direction.outgoing && i.state.in( + ItemState.validStates + ) ).build.query[Int].unique val fileSize = sql""" @@ -113,8 +117,8 @@ object QCollective { val sql = Select( select(t.all).append(count(ti.itemId).s), - from(ti).innerJoin(t, ti.tagId === t.tid), - t.cid === coll + from(ti).innerJoin(t, ti.tagId === t.tid).innerJoin(i, i.id === ti.itemId), + t.cid === coll && i.state.in(ItemState.validStates) ).groupBy(t.name, t.tid, t.category) sql.build.query[TagCount].to[List]