4

I'm in trouble with a simple query to get strings from Realm engine in Java for an Android app. As said in the title of my topic, I want to get diacritic insensitive results from my query.

Example: If user type the word "securite", I want my query to return "securite" and "sécurité".

How can I do that ?

Thanks a lot in advance for your help !

Vinestro
  • 1,072
  • 1
  • 10
  • 32

2 Answers2

2

While Realm doesn't support that currently. Depending on how much of the data you control, you can also add a "normalized" field you can use in your search. There is an approach described here: Remove diacritics from string in Java

Community
  • 1
  • 1
Christian Melchior
  • 19,978
  • 5
  • 62
  • 53
  • Good answer ! I choose your solution and it works well ! I simply created another field in my db table where I put my string "Normalized", then, I normalized the user input and compared the 2 strings, Perfect ! Thanks ! – Vinestro Feb 05 '15 at 07:49
0

This is not possible in Realm at the moment. Your only option is to manage tables containing all the possibilities for each letter of the alphabet you are interested in. Something like [a, á, à, å, etc] and then for each string compute all the possible permutations and build a huge query with equalTo() and or(). It would probably take longer to build such query than to execute it, but that's a very interesting use case! If you end up implementing it I would love to know the results!

Emanuelez
  • 1,651
  • 10
  • 12
  • Thanks for your response ! With this solution, the problem is the following: If I take an array of possible accented "e", [é, è, ë, ê], if the user type "securite", I have to compare each letter of the word to compute possibilities (securite, sécurité, sécurite, securité, ...), but if the user type "sécurité", I have to do the same operation in reverse. I think it maybe too much heavy... But thanks anyway for your help ! – Vinestro Feb 05 '15 at 07:42