Skip to content

Commit

Permalink
Update SearchApiV2Service, fix offset bug fixes #2116
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed May 16, 2020
1 parent aa49afc commit a0c0c84
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions app/Services/SearchApiV2Service.php
Expand Up @@ -86,13 +86,12 @@ protected function resolve()

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') . '%';
$results = Profile::whereNull('status')
->where('username', 'like', $query)
->when($this->query->input('offset') != null, function($q, $offset) {
return $q->offset($offset);
})
->offset($offset)
->limit($limit)
->get();

Expand All @@ -104,13 +103,12 @@ protected function accounts()

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') . '%';
return Hashtag::whereIsBanned(false)
->where('name', 'like', $query)
->when($this->query->input('offset') != null, function($q, $offset) {
return $q->offset($offset);
})
->offset($offset)
->limit($limit)
->get()
->map(function($tag) {
Expand All @@ -124,21 +122,8 @@ protected function hashtags()

protected function statuses()
{
$limit = $this->query->input('limit', 20);
$query = '%' . $this->query->input('q') . '%';
$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();
// Removed until we provide more relevent sorting/results
return [];
}

protected function statusesById()
Expand All @@ -148,9 +133,6 @@ protected function statusesById()
$query = '%' . $this->query->input('q') . '%';
$results = Status::where('caption', 'like', $query)
->whereProfileId($accountId)
->when($this->query->input('offset') != null, function($q, $offset) {
return $q->offset($offset);
})
->limit($limit)
->get();

Expand Down

0 comments on commit a0c0c84

Please sign in to comment.