3

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.

Community
  • 1
  • 1
The Wanderer
  • 3,051
  • 6
  • 29
  • 53
  • If you migrate to PostgreSQL, which is better than Sqlite3 in many ways because it doesn't read from a file, you're going to find many more features to search. I did the same thing for my app, and no regrets, absolutely. If you *do* want to see what Postgres can offer you in terms of search, head over to [this link](https://docs.djangoproject.com/en/4.0/topics/db/search/) – Robo Jan 04 '22 at 13:33

1 Answers1

0

I think this is the closest thing you're going to find, however, it needs some development work:

https://github.com/djcoin/django-unaccent

I'm jealous as well, as my workplace isn't on PostgreSQL either (yet).

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • Thanks for your comment FlipperPA. I posted a follow-up question http://stackoverflow.com/questions/31331629/implementing-accent-insensitive-search-on-django-using-sqlite. Any suggestions? – The Wanderer Jul 10 '15 at 02:45