I have use full text index in my food search and in a food table records are multilingual so i have search with "jamón" (Spanish language) food but it's search end of list and not showing first and show other English language(jamon food) food in top of list so how can i search exact match first then other without take too much time in search query My code like this
$food_data = Nutrition::whereRaw("MATCH(brand_with_name) AGAINST (? IN NATURAL LANGUAGE MODE)", [$item])
->with('guNutrition', 'esNutrition')
->limit($per_page)
->offset($off_set)
->get();
I have use Laravel and Mysql for my app.
I try with following code but it take too much time and not working proper(not showing exact match first then other) with Spanish. only working proper with English
$food_data = Nutrition::whereRaw("MATCH(brand_with_name) AGAINST (? IN NATURAL LANGUAGE MODE)", [$item])
->select('*',\DB::raw('CASE WHEN brand_with_name = "' . $item . '" THEN 1 ELSE 0 END AS score'),\DB::raw('MATCH(brand_with_name) AGAINST ("' . $item . '") AS score2'))
->with('guNutrition', 'esNutrition')
->orderBy('score', 'DESC')
->orderBy('score2', 'DESC')
->limit($per_page)
->offset($off_set)
->get();