Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 具有postgres相似性的Cakephp搜索_Postgresql_Cakephp_Cakephp 3.0 - Fatal编程技术网

Postgresql 具有postgres相似性的Cakephp搜索

Postgresql 具有postgres相似性的Cakephp搜索,postgresql,cakephp,cakephp-3.0,Postgresql,Cakephp,Cakephp 3.0,我想在我的网站上建立一个搜索功能,并通过最佳匹配搜索结果。我正在使用postgres,希望使用similarity()获得分数。 要获得最佳匹配,我使用regexp\u matches() 现在一切都按预期运行,在使用bind()降低sql注入的风险后,我得到了预期的结果 我遇到的问题是括号,因为它们不会被转义,这会导致错误 到目前为止,我的代码是: $search = 'Some Query'; $query->find('active') ->select([

我想在我的网站上建立一个搜索功能,并通过最佳匹配搜索结果。我正在使用postgres,希望使用
similarity()
获得分数。
要获得最佳匹配,我使用
regexp\u matches()

现在一切都按预期运行,在使用
bind()
降低sql注入的风险后,我得到了预期的结果

我遇到的问题是括号,因为它们不会被转义,这会导致错误

到目前为止,我的代码是:

$search = 'Some Query';
$query->find('active')
        ->select([
            'Shops.id',
            'Shops.name',
            'score' => $query->newExpr()->add(
                "similarity(Shops.name, :search)"
            ),
            'regexp' => $query->newExpr()->add(
                "regexp_matches(lower(Shops.name), lower(:search))"
            ),
        ])
        ->bind(':search', $search, 'string')
        ->contain([
            'Currencies' => function (Query $q) {
                return $q->find('active');
            },
        ])
        ->order(['score' => 'DESC'])
        ->limit(ShopsTable::LIMIT_SEARCH);
保存查询是否有良好的做法?

注意:在此之前,我使用了crud查找操作,该操作将正确退出搜索查询

使用当前代码:
一些工厂
S'ome Shop-works
S“ome商店-工厂
一些(商店-不起作用
有些{商店-不起作用