← Back to Stormify Documentation

TextFolding

interface TextFolding

Folds text for case-insensitive (and, if the implementation wants, accent-insensitive) matching of facet filters. The same folding must be applied on both sides of a comparison: column wraps the database column in SQL, value transforms the text on the client side.

Used by:

  • Facet.Type.TEXT filters when the facet is not case-sensitive: the generated condition is column(col) likeOperator ?. The bound pattern is built from the typed text split at the wildcards: each literal piece goes through likeValue and is then escaped, so a folding never sees, removes or alters a wildcard or an escape.

  • Facet.Type.ENUM filters, which match display names on the client side by comparing value of the display name with value of the typed text.

Set it once per Stormify instance through Stormify.textFolding. The default, DEFAULT, is the plain case-insensitive matching of the dialect.

An implementation for a specific language typically uppercases the column and removes diacritics with a database function (TRANSLATE, unaccent, …) in column, and does the same with the platform's text utilities in value. The two must produce the same text for the same input, otherwise filters miss rows.

stormify.textFolding = object : TextFolding {
override fun column(columnExpr: String, dialect: SqlDialect) = "UPPER($columnExpr)"
override fun value(text: String) = text.uppercase()
}

Types

Link copied to clipboard
object Companion

Holds the DEFAULT folding.

Functions

Link copied to clipboard
abstract fun column(columnExpr: String, dialect: SqlDialect): String

Returns the SQL expression that folds columnExpr on the database side.

Link copied to clipboard
open fun likeOperator(dialect: SqlDialect): String

The operator that compares the folded column with the bound text. Defaults to LIKE.

Link copied to clipboard
open fun likeValue(text: String, dialect: SqlDialect): String

Folds the text bound to a LIKE comparison against column. Defaults to value. Override only when the bound text must differ per dialect from the client-side folding.

Link copied to clipboard
abstract fun value(text: String): String

Folds text on the client side, the same way column folds the column.