Improved search performance

This commit is contained in:
Deon George
2022-06-14 16:51:18 +10:00
parent 8777024cd8
commit 606f357839
9 changed files with 27 additions and 104 deletions

View File

@@ -51,9 +51,9 @@ class SearchController extends Controller
foreach (Service::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
->limit(20)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->lid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
$result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]);
}
# Look for an Invoice
@@ -65,36 +65,6 @@ class SearchController extends Controller
$result->push(['name'=>sprintf('%s: %s',$o->lid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
}
# Look for a Broadband Service
foreach (Broadband::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Broadband']);
}
# Look for a Phone Service
foreach (Phone::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Phone']);
}
# Look for Domain Name
foreach (Service\Domain::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('domain_name')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Domains']);
}
if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments
foreach (Payment::Search($request->input('term'))
@@ -105,6 +75,6 @@ class SearchController extends Controller
}
}
return $result;
return $result->sortBy(function($item) { return $item['category'].$item['name']; })->values();
}
}