Przeglądaj źródła

Pharmacy live search - speed optimization

Vijayakrishnan 4 lat temu
rodzic
commit
353462e41c

+ 8 - 8
app/Http/Controllers/HomeController.php

@@ -390,22 +390,22 @@ class HomeController extends Controller
     {
         $term = $request->input('term') ? trim($request->input('term')) : '';
         if (empty($term)) return '';
+        $term = strtolower($term);
         $pharmacies = Facility::where('facility_type', 'Pharmacy')
             ->where(function ($q) use ($term) {
-                $q->orWhere('name', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('address_line1', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('address_line2', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('address_city', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('address_state', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('phone', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('address_zip', 'ILIKE', '%' . $term . '%');
+                $q->orWhereRaw('LOWER(name::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(address_line1::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(address_line2::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(address_city::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(address_state::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(phone::text) LIKE ?', ['%' . $term . '%'])
+                    ->orWhereRaw('LOWER(address_zip::text) LIKE ?', ['%' . $term . '%']);
             })
             ->orderBy('name', 'asc')
             ->orderBy('address_line1', 'asc')
             ->orderBy('address_city', 'asc')
             ->orderBy('address_state', 'asc')
             ->get();
-
         return view('app/pharmacy-suggest', compact('pharmacies'));
     }
 

+ 2 - 2
resources/views/app/patient/partials/pharmacy-suggest.blade.php

@@ -13,9 +13,9 @@ initPharmacySearch: function () {
     };
     var lastTerm = '';
     var returnedFunction = debounce(function () {
-        var term = $.trim($('#pharmacy-search').val());
+        var term = $('#pharmacy-search').val();
         if (!!term && lastTerm !== term) {
-            $.get('/pharmacy-suggest?term=' + term, function (_data) {
+            $.get('/pharmacy-suggest?term=' + $.trim(term), function (_data) {
                 $('.suggestions-outer.pharmacy-suggestions').html(_data).removeClass('d-none');
             });
             lastTerm = term;