jeudi 9 juillet 2015

Accent insensitive search django sqlite

I am using sqlite and django. I am trying to search for accented strings stored in the sqlite database using non-accented search query.

For example: search for "Rio Grande" when the database contains "Río Grande".

I found this SO post SQLite accent-insensitive search that mentions to first create a collation and then call the search query using COLLATE NOACCENTS

This is exactly what I need. However I am not sure how to do this using django models. Any suggestions?

As suggested in this Postgres specific post on django documentation: PostgreSQL specific lookups I tried the following:

myObject.objects.filter(locationTuple__unaccent__contains='Rio Grande')

but got the following error: FieldError: Unsupported lookup 'unaccent' for CharField or join on the field not permitted. which is understandable because this lookup might not work for sqlite.

Aucun commentaire:

Enregistrer un commentaire