問題描述
我在 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模板網!