Browse Source

Update SearchController, fix self search bug and rank local matches first

Daniel Supernault 5 năm trước cách đây
mục cha
commit
f67fada273

+ 5 - 2
app/Http/Controllers/SearchController.php

@@ -194,11 +194,14 @@ class SearchController extends Controller
 
 
         else {
         else {
             $this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) {
             $this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) {
-                $users = Profile::select('domain', 'username', 'name', 'id')
+                if(Str::startsWith($tag, '@')) {
+                    $tag = substr($tag, 1);
+                }
+                $users = Profile::select('status', 'domain', 'username', 'name', 'id')
                     ->whereNull('status')
                     ->whereNull('status')
-                    ->where('id', '!=', Auth::user()->profile->id)
                     ->where('username', 'like', '%'.$tag.'%')
                     ->where('username', 'like', '%'.$tag.'%')
                     ->limit(20)
                     ->limit(20)
+                    ->orderBy('domain')
                     ->get();
                     ->get();
 
 
                 if($users->count() > 0) {
                 if($users->count() > 0) {