views:

247

answers:

1

I've a db that contains some accent characters and i've to do an accent insensitive search as fast as possible. I tried two solutions:

  • query all possible accent combination. For example: perche perchè perché pèrche pérche pèrchè pèrché pérchè pérché

  • rewrite LIKE operator where i first replace all accent characters with their respective normal and then do a comparison as usual.

The first one is obviously too expensive but the second one isn't good enough.

Is there a solution i'm missing?

Thanks Marco

A: 

Some ather approaches. All depends of what you can do on your database.

  • remove all accents from your database at insertion time or in some pre-treatment request.
  • define an sqlite operator that remove accent from field before comparizon.
kriss
I cannot modify data in the database.The LIKE operator replacement does what you suggested, remove accent before comparison.
Marco
can you set an index on the result of the accent removal ? If it's possible you should have huge performance improvement.
kriss
I overlooked a detail in my previous comment : does the like operator performs the unaccented comparison by itself like the name suggest (ie: like(accented, unaccented)) ? If so that's not exactly what I propose. If thought more of an unaccent operator and using common SQL comparizon operators. The difference between the two is that an unaccent parameter can be indexed, not the like form with two arguments.
kriss
I took your hint and i've made a copy of the db with the content diacritic less. Then i query the diacritic less db to get the rowid and finally get right results from original db.
Marco