0

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; 
}
2
  • Have you tried using regex like $search_volume_incomplete = searchVolume::where('kw','regex', new MongoRegex("/^$keyword/i"))->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);? Commented Oct 7, 2015 at 19:14
  • 1
    Don't know whether it works but Class 'App\Models\MongoRegex' not found , this is the error coming, well jessengers is already included, i am looking in the issue but if you know then lemme know , thanks. Commented Oct 8, 2015 at 3:31

1 Answer 1

1

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)->paginate(20);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.