mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Basic poc to search via custom query
This commit is contained in:
@ -5,14 +5,14 @@ import cats.effect.Sync
|
||||
import cats.effect.concurrent.Ref
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.common.{IdRef, _}
|
||||
import docspell.query.ItemQuery
|
||||
import docspell.store.Store
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
import docspell.store.qb.generator.{ItemQueryGenerator, Tables}
|
||||
import docspell.store.records._
|
||||
|
||||
import doobie.implicits._
|
||||
import doobie.{Query => _, _}
|
||||
import org.log4s.getLogger
|
||||
@ -172,10 +172,13 @@ object QItem {
|
||||
.leftJoin(pers1, pers1.pid === i.concPerson && pers1.cid === coll)
|
||||
.leftJoin(equip, equip.eid === i.concEquipment && equip.cid === coll),
|
||||
where(
|
||||
i.cid === coll && or(
|
||||
i.folder.isNull,
|
||||
i.folder.in(QFolder.findMemberFolderIds(q.account))
|
||||
i.cid === coll &&? q.itemIds.map(s =>
|
||||
Nel.fromList(s.toList).map(nel => i.id.in(nel)).getOrElse(i.id.isNull)
|
||||
)
|
||||
&& or(
|
||||
i.folder.isNull,
|
||||
i.folder.in(QFolder.findMemberFolderIds(q.account))
|
||||
)
|
||||
)
|
||||
).distinct.orderBy(
|
||||
q.orderAsc
|
||||
@ -184,7 +187,7 @@ object QItem {
|
||||
)
|
||||
}
|
||||
|
||||
def queryCondition(coll: Ident, q: Query.QueryCond): Condition =
|
||||
def queryCondFromForm(coll: Ident, q: Query.QueryForm): Condition =
|
||||
Condition.unit &&?
|
||||
q.direction.map(d => i.incoming === d) &&?
|
||||
q.name.map(n => i.name.like(QueryWildcard.lower(n))) &&?
|
||||
@ -221,6 +224,19 @@ object QItem {
|
||||
findCustomFieldValuesForColl(coll, q.customValues)
|
||||
.map(itemIds => i.id.in(itemIds))
|
||||
|
||||
def queryCondFromExpr(coll: Ident, q: ItemQuery): Condition = {
|
||||
val tables = Tables(i, org, pers0, pers1, equip, f, a, m)
|
||||
ItemQueryGenerator.fromExpr(tables, coll)(q.expr)
|
||||
}
|
||||
|
||||
def queryCondition(coll: Ident, cond: Query.QueryCond): Condition =
|
||||
cond match {
|
||||
case fm: Query.QueryForm =>
|
||||
queryCondFromForm(coll, fm)
|
||||
case expr: Query.QueryExpr =>
|
||||
queryCondFromExpr(coll, expr.q)
|
||||
}
|
||||
|
||||
def findItems(
|
||||
q: Query,
|
||||
maxNoteLen: Int,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package docspell.store.queries
|
||||
|
||||
import docspell.common._
|
||||
import docspell.query.ItemQuery
|
||||
import docspell.store.qb.Column
|
||||
import docspell.store.records.RItem
|
||||
|
||||
@ -9,14 +10,23 @@ case class Query(fix: Query.Fix, cond: Query.QueryCond) {
|
||||
copy(cond = f(cond))
|
||||
|
||||
def withOrder(orderAsc: RItem.Table => Column[_]): Query =
|
||||
copy(fix = fix.copy(orderAsc = Some(orderAsc)))
|
||||
withFix(_.copy(orderAsc = Some(orderAsc)))
|
||||
|
||||
def withFix(f: Query.Fix => Query.Fix): Query =
|
||||
copy(fix = f(fix))
|
||||
}
|
||||
|
||||
object Query {
|
||||
|
||||
case class Fix(account: AccountId, orderAsc: Option[RItem.Table => Column[_]])
|
||||
case class Fix(
|
||||
account: AccountId,
|
||||
itemIds: Option[Set[Ident]],
|
||||
orderAsc: Option[RItem.Table => Column[_]]
|
||||
)
|
||||
|
||||
case class QueryCond(
|
||||
sealed trait QueryCond
|
||||
|
||||
case class QueryForm(
|
||||
name: Option[String],
|
||||
states: Seq[ItemState],
|
||||
direction: Option[Direction],
|
||||
@ -37,10 +47,10 @@ object Query {
|
||||
itemIds: Option[Set[Ident]],
|
||||
customValues: Seq[CustomValue],
|
||||
source: Option[String]
|
||||
)
|
||||
object QueryCond {
|
||||
) extends QueryCond
|
||||
object QueryForm {
|
||||
val empty =
|
||||
QueryCond(
|
||||
QueryForm(
|
||||
None,
|
||||
Seq.empty,
|
||||
None,
|
||||
@ -64,7 +74,9 @@ object Query {
|
||||
)
|
||||
}
|
||||
|
||||
case class QueryExpr(q: ItemQuery) extends QueryCond
|
||||
|
||||
def empty(account: AccountId): Query =
|
||||
Query(Fix(account, None), QueryCond.empty)
|
||||
Query(Fix(account, None, None), QueryForm.empty)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user