mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-13 23:29:32 +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)
|
final case class CustomFieldMatch(name: String, op: Operator, value: String)
|
||||||
extends Expr
|
extends Expr
|
||||||
|
final case class CustomFieldIdMatch(id: String, op: Operator, value: String)
|
||||||
|
extends Expr
|
||||||
|
|
||||||
final case class Fulltext(query: String) extends Expr
|
final case class Fulltext(query: String) extends Expr
|
||||||
|
|
||||||
|
@ -56,5 +56,7 @@ object ExprUtil {
|
|||||||
expr
|
expr
|
||||||
case CustomFieldMatch(_, _, _) =>
|
case CustomFieldMatch(_, _, _) =>
|
||||||
expr
|
expr
|
||||||
|
case CustomFieldIdMatch(_, _, _) =>
|
||||||
|
expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package docspell.query.internal
|
|||||||
|
|
||||||
import cats.parse.{Parser => P}
|
import cats.parse.{Parser => P}
|
||||||
|
|
||||||
import docspell.query.ItemQuery.Expr.CustomFieldMatch
|
|
||||||
import docspell.query.ItemQuery._
|
import docspell.query.ItemQuery._
|
||||||
|
|
||||||
object SimpleExprParser {
|
object SimpleExprParser {
|
||||||
@ -62,7 +61,13 @@ object SimpleExprParser {
|
|||||||
val customFieldExpr: P[Expr.CustomFieldMatch] =
|
val customFieldExpr: P[Expr.CustomFieldMatch] =
|
||||||
(P.string("f:") *> BasicParser.identParser ~ op ~ BasicParser.singleString).map {
|
(P.string("f:") *> BasicParser.identParser ~ op ~ BasicParser.singleString).map {
|
||||||
case ((name, op), value) =>
|
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] =
|
val inboxExpr: P[Expr.InboxExpr] =
|
||||||
@ -81,6 +86,7 @@ object SimpleExprParser {
|
|||||||
tagIdExpr,
|
tagIdExpr,
|
||||||
tagExpr,
|
tagExpr,
|
||||||
catExpr,
|
catExpr,
|
||||||
|
customFieldIdExpr,
|
||||||
customFieldExpr,
|
customFieldExpr,
|
||||||
inboxExpr,
|
inboxExpr,
|
||||||
dirExpr
|
dirExpr
|
||||||
|
@ -145,7 +145,10 @@ object ItemQueryGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Expr.CustomFieldMatch(field, op, value) =>
|
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(_) =>
|
case Expr.Fulltext(_) =>
|
||||||
// not supported here
|
// not supported here
|
||||||
@ -229,18 +232,21 @@ object ItemQueryGenerator {
|
|||||||
QOp.Lte
|
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 cf = RCustomField.as("cf")
|
||||||
val cfv = RCustomFieldValue.as("cfv")
|
val cfv = RCustomFieldValue.as("cfv")
|
||||||
val v = if (op == QOp.LowerLike) QueryWildcard.lower(value) else value
|
val v = if (op == QOp.LowerLike) QueryWildcard.lower(value) else value
|
||||||
Select(
|
Select(
|
||||||
select(cfv.itemId),
|
select(cfv.itemId),
|
||||||
from(cfv).innerJoin(cf, cf.id === cfv.field),
|
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,
|
cfv.value,
|
||||||
op,
|
op,
|
||||||
v
|
v
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,11 @@ object QueryWildcard {
|
|||||||
else res
|
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
|
|> List.head
|
||||||
|> Maybe.map (Q.ConcEquipId Q.Eq)
|
|> Maybe.map (Q.ConcEquipId Q.Eq)
|
||||||
, whenNotEmpty (Data.CustomFieldChange.toFieldValues model.customValues)
|
, 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.Gte) model.fromDate
|
||||||
, Maybe.map (Q.DateMs Q.Lte) model.untilDate
|
, Maybe.map (Q.DateMs Q.Lte) model.untilDate
|
||||||
, Maybe.map (Q.DueDateMs Q.Gte) model.fromDueDate
|
, Maybe.map (Q.DueDateMs Q.Gte) model.fromDueDate
|
||||||
|
@ -44,6 +44,7 @@ type ItemQuery
|
|||||||
| ConcPersId AttrMatch String
|
| ConcPersId AttrMatch String
|
||||||
| ConcEquipId AttrMatch String
|
| ConcEquipId AttrMatch String
|
||||||
| CustomField AttrMatch CustomFieldValue
|
| CustomField AttrMatch CustomFieldValue
|
||||||
|
| CustomFieldId AttrMatch CustomFieldValue
|
||||||
| DateMs AttrMatch Int
|
| DateMs AttrMatch Int
|
||||||
| DueDateMs AttrMatch Int
|
| DueDateMs AttrMatch Int
|
||||||
| Source AttrMatch String
|
| Source AttrMatch String
|
||||||
@ -153,6 +154,9 @@ render q =
|
|||||||
CustomField m kv ->
|
CustomField m kv ->
|
||||||
"f:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
|
"f:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
|
||||||
|
|
||||||
|
CustomFieldId m kv ->
|
||||||
|
"f.id:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
|
||||||
|
|
||||||
DateMs m ms ->
|
DateMs m ms ->
|
||||||
"date" ++ attrMatch m ++ "ms" ++ String.fromInt ms
|
"date" ++ attrMatch m ++ "ms" ++ String.fromInt ms
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user