我在 laravel 'like' 查询中遇到问题.我在 Laravel 上有一个 MIS,在 MongoDb 上有数据库.现在我的数据库有一个名为 kw
的表,带有像 cars%20in%20London
这样的 urlencoded 关键字,现在我的查询给出了 cars
或 的准确结果>cars%20in%20London
但是当我搜索 cars%20in
时,我得到 0 个结果!这就是在查询中使用 laravel 'like' 的方式,但 Mongo 使用/.m./形式,我该如何使其工作.这是我的模型函数
I am facing an issue in laravel 'like' query. I have a MIS on laravel with databases on MongoDb. Now my DB has a table named kw
with urlencoded keywords like cars%20in%20London
, Now my query gives accurate results for cars
or cars%20in%20London
but when I search cars%20in
I get 0 results! This is how laravel 'like' is used in query but Mongo uses /.m./ form, How can I make this working. Here is my Model function
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;
}
因为在 mongoDb 中没有like"这样的东西,所以我寻找了 Mongodb regex,但是 mongoDB 的 laravel regexp 很有魅力,这是有效的查询.http://jenssegers.be/projects/laravel-mongodb
well as there is no such thing as 'like' in mongoDb, I looked for Mongodb regex, but laravel regexp for mongoDB worked as a charm, here is the query which worked. http://jenssegers.be/projects/laravel-mongodb
$search_volume_unprocessed =searchVolume::where('kw','=',$keyword)->orwhere('kw','regexp',"/.*$keyword/i")->where('status','=',1)->分页(20);
$search_volume_unprocessed = searchVolume::where('kw','=',$keyword)->orwhere('kw','regexp',"/.*$keyword/i")->where('status','=',1)->paginate(20);
这篇关于Laravel 'like' 查询与 MongoDB 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!