Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

How to do a free text search in a portable text field using Sanity.io.

11 replies
Last updated: Jul 6, 2021
How can I do a free text search in a portable text field? Like, I have a schema
with a portable text field
. I want to be able to search
*[_type == "discount"] | score(description match $query) | order(_score desc) [ _score > 0 ]
Jul 6, 2021, 6:55 AM
Hi User! You could use the
function for this purpose:
*[_type == "discount"] | score(pt::text(description) match $query) | order(_score desc) [ _score > 0 ]
More about the function:
Jul 6, 2021, 7:00 AM
and the query:

*[_type == 'discount'] 
  | score(pt::text(description) match $query) | order(_score desc) {
    business -> { name }
  [ _score > 0 ]
Jul 6, 2021, 7:09 AM
oh, and the error I get is:

score() function received unexpected expression
Jul 6, 2021, 7:09 AM
I can confirm that it doesn't seem to be working, although I recall it did before. Will check with our GROQ team. The
function does work in the projection (e.g.
"plaintextDesc": pt::text(description)
) so it might be a regression.
Jul 6, 2021, 7:40 AM
The same query does work on a local project using Vision though, so I'm puzzled. We'll investigate 🙂
Jul 6, 2021, 7:44 AM
Thanks 🙂
Jul 6, 2021, 8:15 AM
Quick update: we've identified the issue and are working on a fix.
Jul 6, 2021, 8:32 AM
I swear to god, you have the best customer service I've ever encountered
Jul 6, 2021, 8:37 AM
user U
the fix is in place and your query should now run successfully 🙂
Jul 6, 2021, 3:55 PM
Great! What was the issue?
Jul 6, 2021, 4:06 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?