In my website i need to provide a search option where user can search for different product. Now i want if search key match with product display it and along with display some suggestion contain with that search keyword separated by space.
list($type,$search) = explode(":", $key);
$searchValues = preg_split('/\s+/', $search, -1, PREG_SPLIT_NO_EMPTY);
ProductDetail::join('product_brands','product_details.brand_id','product_brands.id')
->select('brand_name as manufacturer','product_availability as isInStock','product_details.*','product_price as displayPrice')
->where(function ($q) use ($searchValues,$search) {
$q->where('product_name', 'like', "%{$search}%");
foreach ($searchValues as $value) {
$q->orWhere('product_name', 'like', "%{$value}%");
}
})->paginate(5);
Now problem with this result is, it does't display according to best/first match. so user can't find what they are looking for in the list of other suggestions.
So how to get best matched order?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2G4FLdz
via IFTTT
Aucun commentaire:
Enregistrer un commentaire