0

Please help me to ignore accent sensitive in a Cloudant Query

I found on the internet a method to ignore case sensitive (?i), it works fine. But doesn't work with accent sensitive.

This is a part of my Cloudant Query:

{
  "modelo": { 
     "$regex": "(?i)sábado" 
   }
}

Thanks!!

shA.t
  • 16,580
  • 5
  • 54
  • 111
Rafael Gallardo
  • 143
  • 1
  • 7
  • AFAIK, you can't match accent-insensitive by regex, instead you need to replace those characters before matching by regex -HTH ;). – shA.t Oct 08 '17 at 05:13
  • ok Thanks!! @shA.t. Maybe do u can give me an example of your solution please? thanks again! – Rafael Gallardo Oct 09 '17 at 01:34
  • Possible duplicate of [Query - Case and accent insensitive](https://stackoverflow.com/questions/35546549/query-case-and-accent-insensitive) – shA.t Oct 09 '17 at 10:27

2 Answers2

0

Like the first commenter mentioned you will probably need to replace the characters in your search. For example, you could change your search to something like this

{
  "$or": [
    {"modelo": {"$regex": "(?i)sábado"}},
    {"modelo": {"$regex": "(?i)sabado"}}
  ]
}

If you have control of the data as it is stored in Cloudant it might be easier if you replace the accent characters on the way in. If you need the original value you could add a new field for searching. For example, you go could set modelo to sábado and then add another field like modelo_search and set the value to sabado. Then whenever you perform your search you use the modelo_search field and replace the accents in the search string, like so:

{
  "modelo_search": { 
    "$regex": "(?i)sabado" 
  }
}
markwatsonatx
  • 3,391
  • 2
  • 21
  • 19
  • Thanks for you response, but the thing is that we need that the parameters in the data base have acents because the parameters are in spanish. The search must be accent-insensitive. – Rafael Gallardo Oct 09 '17 at 16:01
0

I found the solution: Just have to change any vowel in the string you want to search for the respective vowel.

var dat = "sábado"
var res = dat.replace(new RegExp(/[aáAÁ]/g), "[aáAÁ]");
Rafael Gallardo
  • 143
  • 1
  • 7