【发布时间】:2016-01-05 00:37:54
【问题描述】:
我在 laravel 'like' 查询中遇到问题。我在 laravel 上有一个带有 MongoDb 数据库的 MIS。现在我的数据库有一个名为kw 的表,其中包含cars%20in%20London 等urlencoded 关键字,现在我的查询给出了cars 或cars%20in%20London 的准确结果,但是当我搜索cars%20in 时,我得到0 个结果!这就是 laravel 'like' 在查询中的使用方式,但 Mongo 使用 /.m./ 形式,我怎样才能使它工作。这是我的模型函数
public static function selectKeywordIncomplete($keyword) {
$search_volume_incomplete = searchVolume::where('kw','like','%'.$keyword.'%')->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);
return $search_volume_incomplete;
}
【问题讨论】:
-
你试过像
$search_volume_incomplete = searchVolume::where('kw','regex', new MongoRegex("/^$keyword/i"))->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);这样的正则表达式吗? -
不知道它是否有效,但未找到 Class 'App\Models\MongoRegex',这是错误来了,已经包括了 jessengers,我正在寻找这个问题,但如果你知道的话让我知道,谢谢。
标签: php mongodb laravel-5 eloquent