mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Search with wildcards for custom fields
This commit is contained in:
@ -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))
|
||||
|
@ -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)
|
||||
|
||||
}
|
Reference in New Issue
Block a user