mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 10:29:34 +00:00
Specificly search for field id vs name
This commit is contained in:
parent
b4b5acde13
commit
a48504debb
@ -103,6 +103,8 @@ object ItemQuery {
|
||||
|
||||
final case class CustomFieldMatch(name: String, op: Operator, value: String)
|
||||
extends Expr
|
||||
final case class CustomFieldIdMatch(id: String, op: Operator, value: String)
|
||||
extends Expr
|
||||
|
||||
final case class Fulltext(query: String) extends Expr
|
||||
|
||||
|
@ -56,5 +56,7 @@ object ExprUtil {
|
||||
expr
|
||||
case CustomFieldMatch(_, _, _) =>
|
||||
expr
|
||||
case CustomFieldIdMatch(_, _, _) =>
|
||||
expr
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package docspell.query.internal
|
||||
|
||||
import cats.parse.{Parser => P}
|
||||
|
||||
import docspell.query.ItemQuery.Expr.CustomFieldMatch
|
||||
import docspell.query.ItemQuery._
|
||||
|
||||
object SimpleExprParser {
|
||||
@ -62,7 +61,13 @@ object SimpleExprParser {
|
||||
val customFieldExpr: P[Expr.CustomFieldMatch] =
|
||||
(P.string("f:") *> BasicParser.identParser ~ op ~ BasicParser.singleString).map {
|
||||
case ((name, op), value) =>
|
||||
CustomFieldMatch(name, op, value)
|
||||
Expr.CustomFieldMatch(name, op, value)
|
||||
}
|
||||
|
||||
val customFieldIdExpr: P[Expr.CustomFieldIdMatch] =
|
||||
(P.string("f.id:") *> BasicParser.identParser ~ op ~ BasicParser.singleString).map {
|
||||
case ((name, op), value) =>
|
||||
Expr.CustomFieldIdMatch(name, op, value)
|
||||
}
|
||||
|
||||
val inboxExpr: P[Expr.InboxExpr] =
|
||||
@ -81,6 +86,7 @@ object SimpleExprParser {
|
||||
tagIdExpr,
|
||||
tagExpr,
|
||||
catExpr,
|
||||
customFieldIdExpr,
|
||||
customFieldExpr,
|
||||
inboxExpr,
|
||||
dirExpr
|
||||
|
@ -145,7 +145,10 @@ object ItemQueryGenerator {
|
||||
}
|
||||
|
||||
case Expr.CustomFieldMatch(field, op, value) =>
|
||||
tables.item.id.in(itemsWithCustomField(coll, field, makeOp(op), value))
|
||||
tables.item.id.in(itemsWithCustomField(_.name ==== field)(coll, makeOp(op), value))
|
||||
|
||||
case Expr.CustomFieldIdMatch(field, op, value) =>
|
||||
tables.item.id.in(itemsWithCustomField(_.id ==== field)(coll, makeOp(op), value))
|
||||
|
||||
case Expr.Fulltext(_) =>
|
||||
// not supported here
|
||||
@ -229,18 +232,21 @@ object ItemQueryGenerator {
|
||||
QOp.Lte
|
||||
}
|
||||
|
||||
def itemsWithCustomField(coll: Ident, field: String, op: QOp, value: String): Select = {
|
||||
private def itemsWithCustomField(
|
||||
sel: RCustomField.Table => Condition
|
||||
)(coll: Ident, op: QOp, value: String): Select = {
|
||||
val cf = RCustomField.as("cf")
|
||||
val cfv = RCustomFieldValue.as("cfv")
|
||||
val v = if (op == QOp.LowerLike) QueryWildcard.lower(value) else value
|
||||
Select(
|
||||
select(cfv.itemId),
|
||||
from(cfv).innerJoin(cf, cf.id === cfv.field),
|
||||
cf.cid === coll && (cf.name ==== field || cf.id ==== field) && Condition.CompareVal(
|
||||
cf.cid === coll && sel(cf) && Condition.CompareVal(
|
||||
cfv.value,
|
||||
op,
|
||||
v
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,4 +19,11 @@ object QueryWildcard {
|
||||
else res
|
||||
}
|
||||
|
||||
def atEnd(s: String): String =
|
||||
if (s.endsWith("*")) s"${s.dropRight(1)}%"
|
||||
else s
|
||||
|
||||
def addAtEnd(s: String): String =
|
||||
if (s.endsWith("*")) atEnd(s)
|
||||
else s"${s}%"
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ getItemQuery model =
|
||||
|> List.head
|
||||
|> Maybe.map (Q.ConcEquipId Q.Eq)
|
||||
, whenNotEmpty (Data.CustomFieldChange.toFieldValues model.customValues)
|
||||
(List.map (Q.CustomField Q.Like) >> Q.And)
|
||||
(List.map (Q.CustomFieldId Q.Like) >> Q.And)
|
||||
, Maybe.map (Q.DateMs Q.Gte) model.fromDate
|
||||
, Maybe.map (Q.DateMs Q.Lte) model.untilDate
|
||||
, Maybe.map (Q.DueDateMs Q.Gte) model.fromDueDate
|
||||
|
@ -44,6 +44,7 @@ type ItemQuery
|
||||
| ConcPersId AttrMatch String
|
||||
| ConcEquipId AttrMatch String
|
||||
| CustomField AttrMatch CustomFieldValue
|
||||
| CustomFieldId AttrMatch CustomFieldValue
|
||||
| DateMs AttrMatch Int
|
||||
| DueDateMs AttrMatch Int
|
||||
| Source AttrMatch String
|
||||
@ -153,6 +154,9 @@ render q =
|
||||
CustomField m kv ->
|
||||
"f:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
|
||||
|
||||
CustomFieldId m kv ->
|
||||
"f.id:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
|
||||
|
||||
DateMs m ms ->
|
||||
"date" ++ attrMatch m ++ "ms" ++ String.fromInt ms
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user