gpt4 book ai didi

mysql - cakephp 在具有多个搜索关键字的单列上查询 find_in_set 不起作用

转载 作者:行者123 更新时间:2023-11-29 18:34:52 25 4
gpt4 key购买 nike

我想从列中查找与列数据有任何关键字匹配的所有记录:

如果在具有逗号分隔值的列中搜索单个搜索关键字,则效果很好,如下代码:Cakephp 3.4 版本

$posts = TableRegistry::get('Posts');
$search_keywords = array_filter(explode(' ', $search_string));
$option = [
'contain' => false,
'conditions' => [
"find_in_set('New', Posts.title)",
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();

注意:我希望字符串中的所有单词都应该使用列标题进行搜索,不强制要求有逗号分隔的记录:

$search_keyword = "New car in new delhi";

所以我希望代码如下:

$search_keyword = "New car in new delhi";
$search_keywords = array_filter(explode(' ', $search_string));
$option = [
'contain' => false,
'conditions' => [
"find_in_set({$search_keywords}, `Posts`.title)",
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();

非常感谢!

最佳答案

我找到了解决方案:

首先创建列全文索引,然后添加以下代码:

$search_string = "New car in new delhi";
$option = [
'contain' => false,
'conditions' => [
"MATCH (title) AGAINST ('$search_string')"
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();

关于mysql - cakephp 在具有多个搜索关键字的单列上查询 find_in_set 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45387923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com