简体   繁体   English

django-tastypie-mysql中区分大小写搜索面临的问题

[英]Facing issue with Case sensitive search in django-tastypie-mysql

I am facing problem on Case insensitive search. 我在不区分大小写的搜索中遇到问题。 I am using the following environment:- 我正在使用以下环境:

Database: MySQL
Collation/Character Encoding: utf8bin
Framework: Django-Tastypie

This collation/Character encoding does not support the case insensitive search. 排序规则/字符编码不支持不区分大小写的搜索。 So If I write 所以如果我写

SELECT .... WHERE company_name LIKE '%StackOverflow%';

then it wont give output for 'STACKOVERFLOW' or other combinations. 那么它将不会给出“ STACKOVERFLOW”或其他组合的输出。

When I use Django-Tastypie filtering :- 当我使用Django-Tastypie过滤时:-

company_name__icontains = 'StackOverflow'

And It internally fires same SQL query, hence it doesn't give the correct answer. 并且它在内部触发相同的SQL查询,因此没有给出正确的答案。

If I use simple MySQL query then I might use: 如果我使用简单的MySQL查询,则可以使用:

SELECT .... WHERE UPPER(company_name) like upper('%StackOverflow%');

But not able to write filter for above solution in the Django-Tastypie. 但是无法在Django-Tastypie中为上述解决方案编写过滤器。

I found one alternative way to solve the issue using Regex:- 我找到了一种使用Regex解决问题的替代方法:-

company_name__iregex = '(S|s)(T|t)(A|a)(C|c)(K|k)(O|o)(V|v)(E|e)(R|r)(F|f)(L|l)(O|o)(W|w)'

However, it is very slow method. 但是,这是非常慢的方法。

Can someone give the solution, so that I can build a filter in Tastypie for Case Insensitive Search. 有人可以提供解决方案,以便我可以在Tastypie中为不区分大小写的搜索构建一个过滤器。

Thanks 谢谢

I had changed the character_encoding in the database level. 我已经在数据库级别更改了character_encoding。 Which support case insensitive search. 哪个支持不区分大小写的搜索。

I ran following command:- 我执行以下命令:

alter table {{table_name}} convert to character set utf8 collate utf8_general_ci;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM