1
0
Fork 0
forked from mirror/pixelfed

Update SearchApiV2Service, fix offset bug fixes #2116

This commit is contained in:
Daniel Supernault 2020-05-15 21:05:41 -06:00
parent aa49afc755
commit a0c0c84d3d
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -86,13 +86,12 @@ class SearchApiV2Service
protected function accounts() protected function accounts()
{ {
$limit = $this->query->input('limit', 20); $limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0;
$query = '%' . $this->query->input('q') . '%'; $query = '%' . $this->query->input('q') . '%';
$results = Profile::whereNull('status') $results = Profile::whereNull('status')
->where('username', 'like', $query) ->where('username', 'like', $query)
->when($this->query->input('offset') != null, function($q, $offset) { ->offset($offset)
return $q->offset($offset);
})
->limit($limit) ->limit($limit)
->get(); ->get();
@ -104,13 +103,12 @@ class SearchApiV2Service
protected function hashtags() protected function hashtags()
{ {
$limit = $this->query->input('limit', 20); $limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0;
$query = '%' . $this->query->input('q') . '%'; $query = '%' . $this->query->input('q') . '%';
return Hashtag::whereIsBanned(false) return Hashtag::whereIsBanned(false)
->where('name', 'like', $query) ->where('name', 'like', $query)
->when($this->query->input('offset') != null, function($q, $offset) { ->offset($offset)
return $q->offset($offset);
})
->limit($limit) ->limit($limit)
->get() ->get()
->map(function($tag) { ->map(function($tag) {
@ -124,21 +122,8 @@ class SearchApiV2Service
protected function statuses() protected function statuses()
{ {
$limit = $this->query->input('limit', 20); // Removed until we provide more relevent sorting/results
$query = '%' . $this->query->input('q') . '%'; return [];
$results = Status::where('caption', 'like', $query)
->whereScope('public')
->when($this->query->input('offset') != null, function($q, $offset) {
return $q->offset($offset);
})
->limit($limit)
->orderByDesc('created_at')
->get();
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Collection($results, new StatusTransformer());
return $fractal->createData($resource)->toArray();
} }
protected function statusesById() protected function statusesById()
@ -148,9 +133,6 @@ class SearchApiV2Service
$query = '%' . $this->query->input('q') . '%'; $query = '%' . $this->query->input('q') . '%';
$results = Status::where('caption', 'like', $query) $results = Status::where('caption', 'like', $query)
->whereProfileId($accountId) ->whereProfileId($accountId)
->when($this->query->input('offset') != null, function($q, $offset) {
return $q->offset($offset);
})
->limit($limit) ->limit($limit)
->get(); ->get();