Hyb*_*rid 3 python django postgresql orm
因此,我尝试在同一模型过滤器中使用__unaccent和__search,但这样做时收到错误。我正在尝试使用术语“Pokemon”来匹配术语“Pok\xc3\xa9mon”(注意“\xc3\xa9”)
Game.objects.filter(title__unaccent__icontains="Pokemon")工作正常,但是当我使用时Game.objects.filter(title__unaccent__search="Pokemon),出现以下错误:
\n\n\n/autocomplete-games/ 函数 unaccent(tsquery) 处出现编程错误
\n\n不存在 第 1 行: ...ALESCE(UNACCENT("main_game"."title"), \'\'))\n @@ (UNACCENT(p...\n ^ 提示:没有函数与给定名称匹配和参数类型。您可能需要\n 添加显式类型转换。
\n
我在用:
\n\nPython 3.5
\n\n姜戈 1.10
\n\nPostgreSQL(已安装非重音扩展)
\n执行此操作的方法是在数据库中定义自定义搜索配置,例如:
CREATE TEXT SEARCH CONFIGURATION unaccent ( COPY = french );
ALTER TEXT SEARCH CONFIGURATION unaccent ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple;
Run Code Online (Sandbox Code Playgroud)
我不是 postgres 专家,但这个配置对我有用。有关更多详细信息,请查看如下教程:http://www.nomadblue.com/blog/django/from-like-to-full-text-search-part-ii/
然后在 Django 中使用它:
from django.contrib.postgres.search import SearchVector, SearchQuery
Game.objects.annotate(unaccent_title=SearchVector('title', config='unaccent')).filter(unaccent_title=SearchQuery('Pokemon', config='unaccent'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2380 次 |
| 最近记录: |