👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Issue with searching for text containing a dash in Slack thread

2 replies
Last updated: Mar 13, 2024
When using match to search for text, the whole thing breaks if there is a dash in the query string.
E.g. searching for “e sport” works, but searching for “e-sport” gives no results, even though the content I’m searching for is titled “e-sport”.

Ideas?
Mar 13, 2024, 11:02 AM
Matching this way isn’t the intended use of the
match
operator because of the way it tokenizes characters. More discussion on that here . Using the
string::startsWith()
function doesn’t tokenize the argument and will get you the results you’re looking for!
Mar 13, 2024, 4:28 PM
So
string::split(title, $term)[-1] == ""

How would I do that for searching multiple fields?

Is an alternative to just remove any offending characters before passing the query to match?
Mar 13, 2024, 8:25 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?