Search with wildcards for custom fields

This commit is contained in:
Eike Kettner
2020-11-24 21:29:51 +01:00
parent c389c8fe66
commit a18ac17f0c
2 changed files with 19 additions and 1 deletions

View File

@ -95,7 +95,9 @@ object OCustomFields {
private[this] val logger = Logger.log4s[ConnectionIO](getLogger)
def findAll(coll: Ident, nameQuery: Option[String]): F[Vector[CustomFieldData]] =
store.transact(QCustomField.findAllLike(coll, nameQuery.filter(_.nonEmpty)))
store.transact(
QCustomField.findAllLike(coll, nameQuery.map(WildcardString.apply).map(_.both))
)
def findById(coll: Ident, field: Ident): F[Option[CustomFieldData]] =
store.transact(QCustomField.findById(field, coll))

View File

@ -0,0 +1,16 @@
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*"
}
object WildcardString {
def apply(in: String): WildcardString =
new WildcardString(in.trim)
}