From c2170d2daf5dd4546103baf51d41f999e4de22d3 Mon Sep 17 00:00:00 2001 From: eikek Date: Thu, 3 Jun 2021 21:44:55 +0200 Subject: [PATCH] Fix tag category search being case insensitive --- .../main/scala/docspell/store/qb/DSL.scala | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/store/src/main/scala/docspell/store/qb/DSL.scala b/modules/store/src/main/scala/docspell/store/qb/DSL.scala index c8a883f4..d6f32d9c 100644 --- a/modules/store/src/main/scala/docspell/store/qb/DSL.scala +++ b/modules/store/src/main/scala/docspell/store/qb/DSL.scala @@ -147,6 +147,15 @@ trait DSL extends DoobieMeta { if (cs.isEmpty) c else and(c, cs: _*) + implicit final class StringColumnOps(col: Column[String]) { + def lowerEq(value: String): Condition = + Condition.CompareVal(col, Operator.LowerEq, value.toLowerCase) + + def like(value: String): Condition = + Condition.CompareVal(col, Operator.LowerLike, value.toLowerCase) + + } + implicit final class ColumnOps[A](col: Column[A]) { def s: SelectExpr = SelectExpr.SelectColumn(col, None) @@ -176,13 +185,13 @@ trait DSL extends DoobieMeta { def ===(value: A)(implicit P: Put[A]): Condition = Condition.CompareVal(col, Operator.Eq, value) - def lowerEq(value: A)(implicit P: Put[A]): Condition = + def lowerEqA(value: A)(implicit P: Put[A]): Condition = Condition.CompareVal(col, Operator.LowerEq, value) def ====(value: String): Condition = Condition.CompareVal(col.cast[String], Operator.Eq, value) - def like(value: A)(implicit P: Put[A]): Condition = + def likeA(value: A)(implicit P: Put[A]): Condition = Condition.CompareVal(col, Operator.LowerLike, value) def likes(value: String): Condition = @@ -215,10 +224,16 @@ trait DSL extends DoobieMeta { def notIn(values: Nel[A])(implicit P: Put[A]): Condition = in(values).negate - def inLower(values: Nel[A])(implicit P: Put[A]): Condition = + def inLower(values: Nel[String]): Condition = + Condition.InValues(col.s, values.map(_.toLowerCase), true) + + def inLowerA(values: Nel[A])(implicit P: Put[A]): Condition = Condition.InValues(col.s, values, true) - def notInLower(values: Nel[A])(implicit P: Put[A]): Condition = + def notInLower(values: Nel[String]): Condition = + Condition.InValues(col.s, values.map(_.toLowerCase), true).negate + + def notInLowerA(values: Nel[A])(implicit P: Put[A]): Condition = Condition.InValues(col.s, values, true).negate def isNull: Condition =