mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 02:49:32 +00:00
Fix search summary to restrict on valid items
This commit is contained in:
parent
1d90095707
commit
48d13a35fc
@ -19,7 +19,10 @@ import docspell.store.queries.SearchSummary
|
|||||||
|
|
||||||
import org.log4s.getLogger
|
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[_]] {
|
trait OSimpleSearch[F[_]] {
|
||||||
|
|
||||||
/** Search for items using the given query and optional fulltext
|
/** Search for items using the given query and optional fulltext
|
||||||
@ -268,17 +271,19 @@ object OSimpleSearch {
|
|||||||
|
|
||||||
def searchSummary(
|
def searchSummary(
|
||||||
useFTS: Boolean
|
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 {
|
fulltextQuery match {
|
||||||
case Some(ftq) if useFTS =>
|
case Some(ftq) if useFTS =>
|
||||||
if (q.isEmpty)
|
if (q.isEmpty)
|
||||||
fts.findIndexOnlySummary(q.fix.account, OFulltext.FtsInput(ftq))
|
fts.findIndexOnlySummary(q.fix.account, OFulltext.FtsInput(ftq))
|
||||||
else
|
else
|
||||||
fts
|
fts
|
||||||
.findItemsSummary(q, OFulltext.FtsInput(ftq))
|
.findItemsSummary(validItemQuery, OFulltext.FtsInput(ftq))
|
||||||
|
|
||||||
case _ =>
|
case _ =>
|
||||||
is.findItemsSummary(q)
|
is.findItemsSummary(validItemQuery)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,16 @@ object QCollective {
|
|||||||
val q0 = Select(
|
val q0 = Select(
|
||||||
count(i.id).s,
|
count(i.id).s,
|
||||||
from(i),
|
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
|
).build.query[Int].unique
|
||||||
val q1 = Select(
|
val q1 = Select(
|
||||||
count(i.id).s,
|
count(i.id).s,
|
||||||
from(i),
|
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
|
).build.query[Int].unique
|
||||||
|
|
||||||
val fileSize = sql"""
|
val fileSize = sql"""
|
||||||
@ -113,8 +117,8 @@ object QCollective {
|
|||||||
val sql =
|
val sql =
|
||||||
Select(
|
Select(
|
||||||
select(t.all).append(count(ti.itemId).s),
|
select(t.all).append(count(ti.itemId).s),
|
||||||
from(ti).innerJoin(t, ti.tagId === t.tid),
|
from(ti).innerJoin(t, ti.tagId === t.tid).innerJoin(i, i.id === ti.itemId),
|
||||||
t.cid === coll
|
t.cid === coll && i.state.in(ItemState.validStates)
|
||||||
).groupBy(t.name, t.tid, t.category)
|
).groupBy(t.name, t.tid, t.category)
|
||||||
|
|
||||||
sql.build.query[TagCount].to[List]
|
sql.build.query[TagCount].to[List]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user