[英]Case Insensitive search with POstgres Similar To
I have such query in my Django code我的 Django 代码中有这样的查询
cond = self.text_query(field.id, f'''
EXISTS(
SELECT *
FROM {self.fieldvalue_db_view}
WHERE entry_id = {self.db_table}.id AND
{self.fieldvalue_db_view}.field_id = {field.id} AND
{self.fieldvalue_db_view}.{text_search_column} SIMILAR TO %(pattern)s
)
''', dict(pattern='%' + val + '%'))
When什么时候
val = '%%john smith%%' or val = '%%john%smith%%'
it did not return a result like 'John smith', but if它没有返回像 'John smith' 这样的结果,但如果
val = '%%john%smith%|%smith%john%%'
it returns results with 'John smith'.它返回带有“John smith”的结果。
How this case sensitiveness can be solved?如何解决这种区分大小写的问题?
Thanks,谢谢,
you can use ilike
:你可以使用ilike
:
EXISTS(
SELECT
1
FROM
{ self.fieldvalue_db_view }
WHERE
entry_id = { self.db_table }.id
AND { self.fieldvalue_db_view }.field_id = { field.id }
AND { self.fieldvalue_db_view }.{ text_search_column } ILIKE %(pattern) s
)
also you don't need to return all columns when you checking existence of a row, instead pass a constant which is cheaper当您检查行是否存在时,您也不需要返回所有列,而是传递一个更便宜的常量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.