Improve field query and fix mariadb's pickiness with parens

If no query is given, don't search with `like '%'`. MariaDB doesn't
want parens around columns in the GROUP BY clause.
This commit is contained in:
Eike Kettner
2020-11-25 21:06:38 +01:00
parent 52c6659f9f
commit 0919eec3c2
6 changed files with 19 additions and 8 deletions

View File

@ -96,7 +96,10 @@ object OCustomFields {
def findAll(coll: Ident, nameQuery: Option[String]): F[Vector[CustomFieldData]] =
store.transact(
QCustomField.findAllLike(coll, nameQuery.map(WildcardString.apply).map(_.both))
QCustomField.findAllLike(
coll,
nameQuery.map(WildcardString.apply).flatMap(_.both)
)
)
def findById(coll: Ident, field: Ident): F[Option[CustomFieldData]] =

View File

@ -2,10 +2,11 @@ package docspell.backend.ops
final class WildcardString private (str: String) {
def both: String =
if (str.startsWith("\"") && str.endsWith("\"")) str.drop(1).dropRight(1)
else if (str.startsWith("*") || str.endsWith("*")) str
else s"*$str*"
def both: Option[String] =
if (str.startsWith("\"") && str.endsWith("\"")) Some(str.drop(1).dropRight(1))
else if (str.startsWith("*") || str.endsWith("*")) Some(str)
else if (str.trim == "") None
else Some(s"*$str*")
}
object WildcardString {