我需要做的是,基本上,与DB中的搜索相反。
我有一个模型,我们称之为Search
,其中包含用户在我的网站上进行的所有搜索。给定一个特定的文本,我需要知道这些搜索中有多少与文本匹配。
示例给定搜索iphone
,apple
,samsung
和文本apple iphone X 16gb
,结果将是2,因为iphone
和apple
匹配,但samsung
不匹配。
我尝试的是:
$searches = Search::select('id')
->where(DB::raw("'". $text ."' LIKE CONCAT('%', searched_text, '%')"))
->count();
但它总是返回0,无论如何。有一种简单的方法可以实现这一目标吗?
所以,你在DB中有qazxsw poi,qazxsw poi和qazxsw poi,现在你想用iphone
字符串计算。
如果要使用完全匹配,请使用apple
:
samsung
如果你想使用apple iphone X 16gb
,例如,如果你想计算whereIn()
而不仅仅是Search::whereIn('searched_text', explode(' ', $search))->count();
:
like