【问题标题】:How can search records from a box search with special characters on Laravel and psql如何在 Laravel 和 psql 上使用特殊字符从框搜索中搜索记录
【发布时间】:2017-12-21 19:35:05
【问题描述】:

我有一个问题,我有一个框搜索,所有用户都可以从数据库中的表中搜索记录,问题在于特殊字符,因为当数据库中的记录看起来像这样“Canción”用户键入并搜索“Cancion”,结果为空,并没有得到任何结果,但是,显然,如果他们输入“Canción”,他们得到了所有标题为Canción 的记录。功能是这样的;我正在使用 ILIKE 进行比较,但结果并不好。我正在使用 postgres。

public function scopeSearch($query, $search, $option)
    {
        if ($search !="")
        {
            if ($option == 'all')
            {
                 $query->where('title', 'Ilike', '%' . $search . '%')
                 ->orWhere('author', 'Ilike', '%' . $search . '%')
                 ->orWhere('description', 'Ilike', '%' . $search . '%')
                 ->orWhere('keywords', 'Ilike', '%' . $search . '%')
                 ->orWhere('section', 'Ilike', '%' . $search . '%');
            }
            else
            {
                $query->where($option, 'ILIKE', '%' . $search . '%');
            }

        }
    }

感谢您的帮助。不胜感激

【问题讨论】:

    标签: php laravel psql


    【解决方案1】:

    这不是你可以单独使用 Laravel 直接解决的问题。也许 Postgres 的 unaccent 功能可以解决问题。我自己从未使用过它,但我认为它可能是您正在寻找的东西。

    https://www.postgresql.org/docs/9.1/static/unaccent.html

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 2017-05-22
      • 2018-08-24
      相关资源
      最近更新 更多