重音不敏感搜索django sqlite [英] Accent insensitive search django sqlite

查看:469
本文介绍了重音不敏感搜索django sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sqlite和django。我正在使用非重音搜索查询来搜索存储在sqlite数据库中的重音字符串。



例如:当数据库包含RíoGrande时,搜索Rio Grande。



我发现这个帖子 SQLite不区分大小写搜索,首先创建一个排序规则,然后使用 COLLATE NOACCENTS

这正是我需要的。然而,我不知道如何使用django模型。任何建议?



正如本文中Postgres具体发布的django文档所示: PostgreSQL特定查找我尝试了以下内容:

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

但是以下错误:
FieldError:不支持查找CharField的不重要或不允许的字段加入。这是可以理解的,因为此查找可能不适用于sqlite。

解决方案

我认为这是你要找的最接近的事情,但需要一些开发工作:



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



我也很嫉妒,因为我的工作场所不在Postgre SQL(还)。


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.

解决方案

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).

这篇关于重音不敏感搜索django sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆