mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
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:
@ -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]] =
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user