
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis behavior you're experiencing is actually expected with how the match operator in GROQ handles tokenization and wildcards. The key is understanding that match performs full-text search with tokenization, not substring matching.
When you search for "optimization" (the full word), it matches documents containing that complete token. However, when you search for "optim" (the shorter version), you're likely expecting it to match as a prefix, but match doesn't do automatic prefix matching - it looks for the exact token "optim".
The match operator tokenizes both your search term and the content being searched. It breaks text into discrete tokens (words) based on word boundaries. So:
"optimization" matches documents that contain the token "optimization""optim" only matches documents that contain the exact token "optim" (not as a prefix)If you want prefix matching behavior, you need to explicitly use the wildcard *:
// This will match "optim", "optimization", "optimal", "optimize", etc.
*[title match "optim*"]
// Without wildcard - only matches exact token "optim"
*[title match "optim"]The match operator splits text based on word boundaries and special characters. For example, "banana@sanity.io" would be indexed as separate tokens: ['banana', 'sanity', 'io']. The wildcard * is treated as a word character, and the operator honors Unicode word segmentation rules.
So your queries should look like:
// For prefix matching (will match "optimization", "optimize", etc.)
*[_type == "article" && title match $query + "*"]
// Or if query is already a parameter
*[_type == "article" && title match "optim*"]If you need more precise prefix matching without tokenization behavior, consider using the string::startsWith() function instead:
*[_type == "article" && string::startsWith(lower(title), lower($query))]This gives you true prefix matching without the tokenization behavior of match, though it won't benefit from the full-text search indexing that match uses.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store