Laravel mongoDB partial search

  laravel, mongodb, search

Trying to make a partial search on an indexed field.
I use Laravel 6.9.

I ‘ve created a field for every document in my collection that consists of the data of 5 other fields seperated with a ~.
For example name~surname~address~phone~mobile.
I created just one field so that i can make the search faster. This way i will search just one field instead of 5.

When i search for a specific name lets say John i’m getting results but when i search for Joh i get no results.

I use a whereraw to query the database whereRaw(array('$text'=>array('$search'=> """ . $term . """)))

Searched a lot for partial search but i’m not sure on if and how to do it.

Source: Laravel

Leave a Reply