12
12
use League \Fractal \Pagination \IlluminatePaginatorAdapter ;
13
13
use App \Util \ActivityPub \Helpers ;
14
14
use Illuminate \Support \Str ;
15
+ use App \Services \AccountService ;
16
+ use App \Services \HashtagService ;
17
+ use App \Services \StatusService ;
15
18
16
19
class SearchApiV2Service
17
20
{
@@ -86,19 +89,27 @@ protected function resolve()
86
89
87
90
protected function accounts ()
88
91
{
92
+ $ user = request ()->user ();
89
93
$ limit = $ this ->query ->input ('limit ' ) ?? 20 ;
90
94
$ offset = $ this ->query ->input ('offset ' ) ?? 0 ;
91
95
$ query = '% ' . $ this ->query ->input ('q ' ) . '% ' ;
92
- $ results = Profile::whereNull ('status ' )
96
+ $ results = Profile::select ('profiles.* ' , 'followers.profile_id ' , 'followers.created_at ' )
97
+ ->whereNull ('status ' )
98
+ ->leftJoin ('followers ' , function ($ join ) use ($ user ) {
99
+ return $ join ->on ('profiles.id ' , '= ' , 'followers.following_id ' )
100
+ ->where ('followers.profile_id ' , $ user ->profile_id );
101
+ })
93
102
->where ('username ' , 'like ' , $ query )
103
+ ->orderByDesc ('profiles.followers_count ' )
104
+ ->orderByDesc ('followers.created_at ' )
94
105
->offset ($ offset )
95
106
->limit ($ limit )
96
- ->get ();
107
+ ->get ()
108
+ ->map (function ($ res ) {
109
+ return AccountService::get ($ res ['id ' ]);
110
+ });
97
111
98
- $ fractal = new Fractal \Manager ();
99
- $ fractal ->setSerializer (new ArraySerializer ());
100
- $ resource = new Fractal \Resource \Collection ($ results , new AccountTransformer ());
101
- return $ fractal ->createData ($ resource )->toArray ();
112
+ return $ results ;
102
113
}
103
114
104
115
protected function hashtags ()
@@ -115,6 +126,7 @@ protected function hashtags()
115
126
return [
116
127
'name ' => $ tag ->name ,
117
128
'url ' => $ tag ->url (),
129
+ 'count ' => HashtagService::count ($ tag ->id ),
118
130
'history ' => []
119
131
];
120
132
});
@@ -134,12 +146,11 @@ protected function statusesById()
134
146
$ results = Status::where ('caption ' , 'like ' , $ query )
135
147
->whereProfileId ($ accountId )
136
148
->limit ($ limit )
137
- ->get ();
138
-
139
- $ fractal = new Fractal \Manager ();
140
- $ fractal ->setSerializer (new ArraySerializer ());
141
- $ resource = new Fractal \Resource \Collection ($ results , new StatusTransformer ());
142
- return $ fractal ->createData ($ resource )->toArray ();
149
+ ->get ()
150
+ ->map (function ($ status ) {
151
+ return StatusService::get ($ status ->id );
152
+ });
153
+ return $ results ;
143
154
}
144
155
145
156
protected function resolveQuery ()
@@ -213,4 +224,4 @@ protected function resolveLocalProfile()
213
224
];
214
225
}
215
226
216
- }
227
+ }
0 commit comments