带希腊字符的Django搜索

2024-10-01 15:41:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在django应用程序中尝试了很多后端,总是使用uncent扩展

django文档提到,如果您搜索:

Author.objects.filter(name__unaccent__icontains='Helen')
You get this:
[<Author: Helen Mirren>, <Author: Helena Bonham Carter>, <Author: Hélène Joy>]

但这怎么也适用于希腊文字呢? 我有一个标题为title='σονπερ' 当我这样搜索的时候

Product.objects.filter(title_el__unaccent__icontains='σουπερ')

我明白了:

<ProductQuerySet [<Product: σουπερ>]>

但如果我这样搜索:

Product.objects.filter(title_el__unaccent__icontains='σούπερ')

我明白了:

<ProductQuerySet []>

因此,uncent可能只适用于英语字符(django文档中的西班牙语是英语字符)?如果是的话,我如何扩展希腊字符的功能


Tags: django文档应用程序objectstitleproductfilter字符
1条回答
网友
1楼 · 发布于 2024-10-01 15:41:25

PostgreSQL 12 Uncent支持开箱即用的希腊字符,对于较低版本,您应该自己添加规则

来自unaccent文档

RULES is the base name of the file containing the list of translation rules. This file must be stored in $SHAREDIR/tsearch_data/ (where $SHAREDIR means the PostgreSQL installation's shared-data directory). Its name must end in .rules (which is not to be included in the RULES parameter).

您可以使用已在注释中链接的gist文件

相关问题 更多 >

    热门问题