Merge pull request #575 from eikek/category-search-fix

Category search fix
This commit is contained in:
mergify[bot] 2021-01-17 20:28:06 +00:00 committed by GitHub
commit ffbec3502f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 3 deletions

View File

@ -1,10 +1,12 @@
package docspell.analysis.nlp package docspell.analysis.nlp
import cats.Applicative
import scala.jdk.CollectionConverters._ import scala.jdk.CollectionConverters._
import cats.Applicative
import cats.effect._ import cats.effect._
import docspell.common._ import docspell.common._
import edu.stanford.nlp.pipeline.{CoreDocument, StanfordCoreNLP} import edu.stanford.nlp.pipeline.{CoreDocument, StanfordCoreNLP}
object StanfordNerClassifier { object StanfordNerClassifier {

View File

@ -164,6 +164,9 @@ trait DSL extends DoobieMeta {
def ===(value: A)(implicit P: Put[A]): Condition = def ===(value: A)(implicit P: Put[A]): Condition =
Condition.CompareVal(col, Operator.Eq, value) 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 = def ====(value: String): Condition =
Condition.CompareVal(col.asInstanceOf[Column[String]], Operator.Eq, value) Condition.CompareVal(col.asInstanceOf[Column[String]], Operator.Eq, value)

View File

@ -5,6 +5,7 @@ sealed trait Operator
object Operator { object Operator {
case object Eq extends Operator case object Eq extends Operator
case object LowerEq extends Operator
case object Neq extends Operator case object Neq extends Operator
case object Gt extends Operator case object Gt extends Operator
case object Lt extends Operator case object Lt extends Operator

View File

@ -69,6 +69,8 @@ object ConditionBuilder {
val colFrag = op match { val colFrag = op match {
case Operator.LowerLike => case Operator.LowerLike =>
lower(col) lower(col)
case Operator.LowerEq =>
lower(col)
case _ => case _ =>
SelectExprBuilder.column(col) SelectExprBuilder.column(col)
} }
@ -80,6 +82,8 @@ object ConditionBuilder {
val dbfFrag = op match { val dbfFrag = op match {
case Operator.LowerLike => case Operator.LowerLike =>
lower(dbf) lower(dbf)
case Operator.LowerEq =>
lower(dbf)
case _ => case _ =>
DBFunctionBuilder.build(dbf) DBFunctionBuilder.build(dbf)
} }
@ -89,6 +93,8 @@ object ConditionBuilder {
val (c1Frag, c2Frag) = op match { val (c1Frag, c2Frag) = op match {
case Operator.LowerLike => case Operator.LowerLike =>
(lower(c1), lower(c2)) (lower(c1), lower(c2))
case Operator.LowerEq =>
(lower(c1), lower(c2))
case _ => case _ =>
(SelectExprBuilder.column(c1), SelectExprBuilder.column(c2)) (SelectExprBuilder.column(c1), SelectExprBuilder.column(c2))
} }
@ -131,6 +137,8 @@ object ConditionBuilder {
op match { op match {
case Operator.Eq => case Operator.Eq =>
fr" =" fr" ="
case Operator.LowerEq =>
fr" ="
case Operator.Neq => case Operator.Neq =>
fr" <>" fr" <>"
case Operator.Gt => case Operator.Gt =>

View File

@ -36,7 +36,7 @@ object TagItemName {
def itemsInAllCategories(cats: NonEmptyList[String]): Select = def itemsInAllCategories(cats: NonEmptyList[String]): Select =
intersect( 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 = def itemsWithEitherTag(tags: NonEmptyList[Ident]): Select =