Skip to content

Commit

Permalink
The search:results tag supports pagination. Maintain query string on …
Browse files Browse the repository at this point in the history
…paginator in tags.
  • Loading branch information
jasonvarga committed Nov 20, 2020
1 parent b2ce703 commit d059bc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Search/Tags.php
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Search;

use Illuminate\Contracts\Pagination\Paginator;
use Statamic\Facades\Search;
use Statamic\Facades\Site;
use Statamic\Tags\Concerns;
Expand All @@ -12,6 +13,10 @@ class Tags extends BaseTags
use Concerns\OutputsItems,
Concerns\QueriesConditions;

use Concerns\GetsQueryResults {
results as getQueryResults;
}

protected static $handle = 'search';

public function results()
Expand All @@ -31,14 +36,15 @@ public function results()
$this->queryStatus($builder);
$this->queryConditions($builder);

$results = $this->addResultTypes($builder->get());
$results = $this->getQueryResults($builder);
$results = $this->addResultTypes($results);

return $this->output($results);
}

protected function addResultTypes($results)
{
return $results->map(function ($result) {
return $results->supplement('result_type', function ($result) {
$type = null;

if ($result instanceof \Statamic\Contracts\Entries\Entry) {
Expand All @@ -49,9 +55,7 @@ protected function addResultTypes($results)
$type = 'asset';
}

$result->set('result_type', $type);

return $result;
return $type;
});
}

Expand Down
1 change: 1 addition & 0 deletions src/Tags/Concerns/OutputsItems.php
Expand Up @@ -34,6 +34,7 @@ protected function extraOutput($items)

protected function paginatedOutput($paginator)
{
$paginator->withQueryString();
$as = $this->params->get('as', $this->defaultAsKey ?? 'results');
$items = $paginator->getCollection()->supplement('total_results', $paginator->total());

Expand Down

0 comments on commit d059bc4

Please sign in to comment.