php - 在查询中搜索没有 UTF-8 字母的 UTF-8 通道
问题描述
当 slug 包含 UTF8 字母时,获得非 utf8 结果的最佳方法是什么?(例如:当我输入slug“Zaidimai”时,从数据库中选择所有像“Žaidimai”和“Zaidimai”的地方)。
当前代码:
$results = DB::table('channels') -> where([['name', 'like', '%' . $slug . '%'], ['status', '=', 'OK']]) -> orWhere([['slug', 'like', '%' . $slug . '%'], ['status', '=', 'OK']]) -> limit(3) -> get();
它工作正常,但是当我尝试通过在搜索栏中输入“Zaidimai”来搜索频道时,它没有显示我想要的频道(Žaidimai)。
解决方案
安装 'unaccent' Postgres 扩展,然后将本机 SQL 与该unaccent
功能一起使用。:slug
是下面查询中的参数。
select <whatever you need>
from channels
where (unaccent("name") ilike '%'||unaccent(:slug)||'%' or unaccent(slug) ilike '%'||unaccent(:slug)||'%')
and status = 'OK'
limit 3;
推荐阅读
- floating-point - 浮点数组 JuliaLang 的标准差
- php - Socrata SELECT/WHERE 适用于 Zip 字段,但不适用于 NYS Attorneys 数据中的 Last_name 字段
- python - python中使用numpy.where的多维数组
- python - 根据来自另一个数据框的多个列条件创建列
- c# - IdentityUser 不包含“名称”的定义
- haskell - 在 Haskell 中将列表拆分为非空子列表
- dom - DOMContentLoaded 没有触发
- javascript - 如何使用 browserify 导入独立模块构建?
- javascript - 为什么带有socket.io的nodejs服务器会导致连接无限循环?
- c# - 如果用户名具有特定权限,则动态打开表单