I am using Laravel jQuery UI autocomplete to search through the database. It works but it's so slow. I know I have 38432 items in my database but I don't know if that is the problem. How do I make the search results come up faster?
public function aa(Request $request){
$term = $request->get('term');
$t=str_replace(" ", ", ", $term);
$tt=str_replace(",", ", ", $term);
//$queries=Profile::distinct('cityandstate','LIKE','%'.$term.'%')->take(5)->get();
$queries = all::where('cityandstate', 'like', $term . '%')->orWhere('cityandstate',$t)->orWhere('cityandstate',$tt)->take(10)->get();
foreach ($queries as $query)
{
$results[] = ['value' => $query->cityandstate ];
}
return response()->json($results);
}
JavaScript:
<script type="text/javascript">
$(document).ready(function(){
$( function() {
$( "#location-input" ).autocomplete({
//html : html,
source: "display-searches",
minLength: 0,
select:function(e,ui) {
$("#location-input").val(ui.item.label);
}
} );
} );
});
</script>