Here's my current code that I'm working on:
public function postsearch(Request $request){
$searchItem=$request['searchItem'];
$searchLocation=$request['searchLocation'];
$criteria=$request['criteria'];
if($criteria == 'schools'){
// $result=schools::whereRaw("MATCH(name,describtion) AGAINST('$searchItem') AND MATCH(location) AGAINST('$searchLocation')")->where('status','')->get();
$result=schools::where('name', 'LIKE', '___'.$searchItem.'___')
->orWhere('location', 'LIKE', '___'.$searchLocation.'___')
->where('status','')->get();
if(count($result)>0){
$count=count($result);
return view('schools', array('result' => $result))->with(array('searchItem'=>$searchItem,'searchLocation'=>$searchLocation,'criteria'=>$criteria,'count'=>$count))->with('searchItem',$searchItem);
}
else{
return view('schools')->with(array('msg'=>'Oops, No result found','count'=>'0','searchItem'=>$searchItem,'searchLocation'=>$searchLocation,'criteria'=>$criteria));
}
}
I've been editing this line:
$result=schools::where('name', 'LIKE', '___'.$searchItem.'___')
->orWhere('location', 'LIKE', '___'.$searchLocation.'___')
->where('status','')->get();
The problem is....there can be a school with the name "Mapua University" located in "Manila". If I search "Mapua", it will show up somewhere in the middle of the search results, not at the top. Schools that don't even contain those exact characters will appear at the top....doesn't make sense. If I search "Mapua" as the query and "Manila" in the location box, I get 0 results. It's as if I can't run a search for a name and location. I could run a search for "teacher" and get schools to show up even if none of those schools have "teacher" in their name. I can run a search for "ateneo" and the school won't show up (even if I can confirm it's in the database).
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire