Using Accents in GROQ Queries and Matching to Documents
10 replies
Last updated: Sep 13, 2021
W
Hi guys, I'm new around here. Congratulations on this great tool!
I have a question and I don't see in the documentation how to solve it. See if anyone knows how I can solve. :)
Match query operator is
case-sensitive 💯👋:
In Spain we use characters like the accent mark "M*é*xico".
I can see that
I have also detected that
Can you think of a way to approach this type of match?Will I have to resort to setting up a search with an engine like ElasticSearch?
THANK YOU
I have a question and I don't see in the documentation how to solve it. See if anyone knows how I can solve. :)
Match query operator is
case-sensitive 💯👋:
*[text match "word"] === *[text match "wORd"]
In Spain we use characters like the accent mark "M*é*xico".
I can see that
*[text match "méxico"]and
*[text match "mexico"]return different results. Match query operator is not accent mark sensitive.My clients sometimes write Mexico (without accent mark) wanting to find México in their result. And yet they find nothing.
I have also detected that
*[text match "e-commerce"]does not return any results with this word in the database, middle dash seems not to recognize it. However
*[text match "*commerce"]this does return results with word "e-commerce".
Can you think of a way to approach this type of match?Will I have to resort to setting up a search with an engine like ElasticSearch?
THANK YOU
Sep 10, 2021, 12:17 PM
G
Hi Willy. Welcome! For the Mexico/México case, you could (1) use the OR operator to match either one:
For the e-commerce case, can you give some details about the
*[text match "méxico" || text match "mexico"], or (2) match
"m*xico", though in some cases that may return false positives.
For the e-commerce case, can you give some details about the
textfield you’re searching in? Using the titles (type: ‘string’)
some e-commerce,
e-commerce and more,
word e-commerce word, and
e-commerce, all four results were returned when I queried
*[title match 'e-commerce'].
Sep 10, 2021, 8:10 PM
W
Geoff! Thanks!I would not have thought of m*xico as an option. It looks great to me.
I’m going to convert any accent mark to *. A false positive is better than nothing
🙂
About e-commerce I send you some screenshots. Using this does not return anything:
THANKS
I’m going to convert any accent mark to *. A false positive is better than nothing
🙂
About e-commerce I send you some screenshots. Using this does not return anything:
*[nuclearMessage match ["*e-commerce*"]] {nuclearMessage}Note that I use asterisks ..
THANKS
Sep 10, 2021, 8:37 PM
G
Are you expecting
e-commerceto make up a larger word? If not, I don’t think you need the asterisks. If you are, I believe your query should work on API version
v2021-03-25(it can be set between the dataset and query URL).
Sep 10, 2021, 9:49 PM
W
I understand. By default I have established the search with asterics, large or small. Thanks for the API version, it works perfect!
Sep 10, 2021, 10:35 PM
W
*[_type=="user" && [nuclearMessage, city, country, website, professionalSkill->title, marketNiche->title] match ["*e-commerce*"]] | order(defined(nuclearMessage) desc, defined(marketNiche) desc, firstname asc) {
...,
"professionalSkill": professionalSkill->title,
"marketNiche": marketNiche->title,
"photo": photo{asset->{url}}
}
Sep 12, 2021, 5:10 PM
W
Hello again
It works great but when I add search by reference attributes it returns nothing. I imagine that I am pushing this feature to the limit, but I wanted to share it with you.
In my tests to find the reason, I have detected the following.
This returns results (API version 2021-03-25):
However this does not return anything (API version 2021-03-25)*:*
I understand that there is no solution, but for sharing it with you.
Best
🔥
user A
,I have been testing the API implementation to solve the ["*e-commerce *"]problem.
It works great but when I add search by reference attributes it returns nothing. I imagine that I am pushing this feature to the limit, but I wanted to share it with you.
In my tests to find the reason, I have detected the following.
This returns results (API version 2021-03-25):
*[_type=="user" && [nuclearMessage, city, country, website] match ["*e-commerce*"]] | order(defined(nuclearMessage) desc, defined(marketNiche) desc, firstname asc) {
...,
"professionalSkill": professionalSkill->title,
"marketNiche": marketNiche->title,
"photo": photo{asset->{url}}
}
However this does not return anything (API version 2021-03-25)*:*
*[_type=="user" && [nuclearMessage, city, country, website, *professionalSkill->title, marketNiche->title*] match ["*e-commerce*"]] | order(defined(nuclearMessage) desc, defined(marketNiche) desc, firstname asc) {
...,
"professionalSkill": professionalSkill->title,
"marketNiche": marketNiche->title,
"photo": photo{asset->{url}}
}
I understand that there is no solution, but for sharing it with you.
Best
🔥
Sep 12, 2021, 5:20 PM
W
Hello again
It works great but when I add search by reference attributes it returns nothing. I imagine that I am pushing this feature to the limit, but I wanted to share it with you.
In my tests to find the reason, I have detected the following.
This returns results (API version 2021-03-25):
However this does not return anything (API version 2021-03-25)*:*
I understand that there is no solution, but for sharing it with you.
Best
🔥
user A
,I have been testing the API implementation to solve the ["*e-commerce *"]problem.
It works great but when I add search by reference attributes it returns nothing. I imagine that I am pushing this feature to the limit, but I wanted to share it with you.
In my tests to find the reason, I have detected the following.
This returns results (API version 2021-03-25):
*[_type=="user" && [nuclearMessage, city, country, website] match ["*e-commerce*"]] | order(defined(nuclearMessage) desc, defined(marketNiche) desc, firstname asc) {
...,
"professionalSkill": professionalSkill->title,
"marketNiche": marketNiche->title,
"photo": photo{asset->{url}}
}
However this does not return anything (API version 2021-03-25)*:*
*[_type=="user" && [nuclearMessage, city, country, website, *professionalSkill->title, marketNiche->title*] match ["*e-commerce*"]] | order(defined(nuclearMessage) desc, defined(marketNiche) desc, firstname asc) {
...,
"professionalSkill": professionalSkill->title,
"marketNiche": marketNiche->title,
"photo": photo{asset->{url}}
}
I understand that there is no solution, but for sharing it with you.
Best
🔥
Sep 12, 2021, 5:20 PM
W
Just to put you in context, this implementation is for a general search engine of a directory of people. Users will search by text for any word or phrase. I can understand that maybe if we want to scale in this search we should implement another technology like Elastic or similar.
What do you think Geoff?
Thank you very much for your time. 🙌
What do you think Geoff?
Thank you very much for your time. 🙌
Sep 12, 2021, 5:25 PM
G
I think it’s related to the fact that
e-commerceis splitting on the
-, though I don’t know why it works in the first case but not when dereferencing in the left side array. You could consider accounting for this when you pass in your terms, so that you’re instead matching
['*e*', '*commerce*'](which hopefully will match in your case).
Sep 12, 2021, 5:52 PM
W
Thanks Geoff
Sep 13, 2021, 8:14 AM
Sanity.io – build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.