From 623a61dbb61dd10a4624469fc6027201eb25c2a7 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 17 Jan 2021 20:10:00 +0100 Subject: [PATCH 1/3] Introduce a lowerEq operator to the query builder --- modules/store/src/main/scala/docspell/store/qb/DSL.scala | 3 +++ .../store/src/main/scala/docspell/store/qb/Operator.scala | 1 + .../scala/docspell/store/qb/impl/ConditionBuilder.scala | 8 ++++++++ 3 files changed, 12 insertions(+) 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 ce28d56e..db80e20b 100644 --- a/modules/store/src/main/scala/docspell/store/qb/DSL.scala +++ b/modules/store/src/main/scala/docspell/store/qb/DSL.scala @@ -164,6 +164,9 @@ 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 = + Condition.CompareVal(col, Operator.LowerEq, value) + def ====(value: String): Condition = Condition.CompareVal(col.asInstanceOf[Column[String]], Operator.Eq, value) diff --git a/modules/store/src/main/scala/docspell/store/qb/Operator.scala b/modules/store/src/main/scala/docspell/store/qb/Operator.scala index 907c2593..47b436ef 100644 --- a/modules/store/src/main/scala/docspell/store/qb/Operator.scala +++ b/modules/store/src/main/scala/docspell/store/qb/Operator.scala @@ -5,6 +5,7 @@ sealed trait Operator object Operator { case object Eq extends Operator + case object LowerEq extends Operator case object Neq extends Operator case object Gt extends Operator case object Lt extends Operator diff --git a/modules/store/src/main/scala/docspell/store/qb/impl/ConditionBuilder.scala b/modules/store/src/main/scala/docspell/store/qb/impl/ConditionBuilder.scala index 3a4e4ede..f110bb92 100644 --- a/modules/store/src/main/scala/docspell/store/qb/impl/ConditionBuilder.scala +++ b/modules/store/src/main/scala/docspell/store/qb/impl/ConditionBuilder.scala @@ -69,6 +69,8 @@ object ConditionBuilder { val colFrag = op match { case Operator.LowerLike => lower(col) + case Operator.LowerEq => + lower(col) case _ => SelectExprBuilder.column(col) } @@ -80,6 +82,8 @@ object ConditionBuilder { val dbfFrag = op match { case Operator.LowerLike => lower(dbf) + case Operator.LowerEq => + lower(dbf) case _ => DBFunctionBuilder.build(dbf) } @@ -89,6 +93,8 @@ object ConditionBuilder { val (c1Frag, c2Frag) = op match { case Operator.LowerLike => (lower(c1), lower(c2)) + case Operator.LowerEq => + (lower(c1), lower(c2)) case _ => (SelectExprBuilder.column(c1), SelectExprBuilder.column(c2)) } @@ -131,6 +137,8 @@ object ConditionBuilder { op match { case Operator.Eq => fr" =" + case Operator.LowerEq => + fr" =" case Operator.Neq => fr" <>" case Operator.Gt => From f0f0e6e0d40be2b27bea56ac0a0e7dadca62d110 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 17 Jan 2021 20:10:24 +0100 Subject: [PATCH 2/3] Search for categories case-insensitive The string was already lowercased, but the comparison was not. Fixes #568 --- .../src/main/scala/docspell/store/records/TagItemName.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/store/src/main/scala/docspell/store/records/TagItemName.scala b/modules/store/src/main/scala/docspell/store/records/TagItemName.scala index 9b7d8b77..71d261bf 100644 --- a/modules/store/src/main/scala/docspell/store/records/TagItemName.scala +++ b/modules/store/src/main/scala/docspell/store/records/TagItemName.scala @@ -36,7 +36,7 @@ object TagItemName { def itemsInAllCategories(cats: NonEmptyList[String]): Select = intersect( - cats.map(cat => Select(ti.itemId.s, taggedItems, t.category === cat).distinct) + cats.map(cat => Select(ti.itemId.s, taggedItems, t.category.lowerEq(cat)).distinct) ) def itemsWithEitherTag(tags: NonEmptyList[Ident]): Select = From b2b8ad625a85e45564530da972f6acf09800879f Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 17 Jan 2021 20:11:58 +0100 Subject: [PATCH 3/3] scalafmt --- .../scala/docspell/analysis/nlp/StanfordNerClassifier.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/analysis/src/main/scala/docspell/analysis/nlp/StanfordNerClassifier.scala b/modules/analysis/src/main/scala/docspell/analysis/nlp/StanfordNerClassifier.scala index b82b1c95..3f196b8e 100644 --- a/modules/analysis/src/main/scala/docspell/analysis/nlp/StanfordNerClassifier.scala +++ b/modules/analysis/src/main/scala/docspell/analysis/nlp/StanfordNerClassifier.scala @@ -1,10 +1,12 @@ package docspell.analysis.nlp -import cats.Applicative - import scala.jdk.CollectionConverters._ + +import cats.Applicative import cats.effect._ + import docspell.common._ + import edu.stanford.nlp.pipeline.{CoreDocument, StanfordCoreNLP} object StanfordNerClassifier {