-- Upload timestamp

-- * Utilities

addTag :: XapianDB -> Document -> Text -> Text -> XapianM ()
addTag db doc prefix (T.map toLower -> tag) = do
    let fullTag = prefix <> tag
        safeTag | T.null prefix = sanitizeTag tag
                | otherwise     = fullTag

    addTerm doc $ fullTag
    unless (safeTag == fullTag) $
        addSynonym db safeTag fullTag

-- | Sanitize a tag by reducing it to the groups of of valid characters,
-- separated by _ characters. If the tag has no valid characters, the result is
-- simply "_" itself.
addTag :: XapianDB -> Document -> Text -> Text -> XapianM ()
addTag db doc prefix (T.map toLower -> tag) = do
    let fullTag = prefix <> tag
        safeTag | T.null prefix = sanitizeTag tag
                | otherwise     = fullTag

    addTerm doc $ fullTag
    unless (safeTag == fullTag) $
        addSynonym db safeTag fullTag

-- | Sanitize a tag by reducing it to the groups of of valid characters,
-- separated by _ characters. If the tag has no valid characters, the result is
-- simply "_" itself.
addTag db doc prefix (T.map toLower -> tag) = do
    let fullTag = prefix <> tag
        safeTag | T.null prefix = sanitizeTag tag
                | otherwise     = fullTag

    addTerm doc $ fullTag
    unless (safeTag == fullTag) $
        addSynonym db safeTag fullTag

-- | Sanitize a tag by reducing it to the groups of of valid characters,
-- separated by _ characters. If the tag has no valid characters, the result is
-- simply "_" itself.