Hi, i'm trying to make a query that ignore case sensitive, ignore diacritic sensitive(accents) and use the same logic that % (percent) in SQL.
I have in my database names like: "Palácio Tiradentes", "Palácio da Cidade", etc. I would like to make a search that ignore those things and use the percent like logic
For example, I would make like this in SQL:
select * from collection where remove_accents(upper(name)) like '%' + remove_accents(upper(query)) + '%'
where + concats string.
I found same semi-solutions:
1. I can use regexp to make the percent logic, like this:
db.col.find( { "name": { $regex: new RegExp(".*" + query + ".*", "i")} } )
This ignore case sensitives and make the percent logic for "containing" query string. But still with accents problem.
2. $text index:
Ok, this can ignore case sensitive and accents. But, in this case I can't use regular expressions in a query like this:
db.col.find( { $text: { $search: ".*rest.*"} } } )
The regular expression isn't interpreted.
Someone has a ideia how can I implement this search query?
Thanks for helping :)