Skip to content

Commit

Permalink
Fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hermo committed Sep 16, 2018
1 parent 84552be commit 0f575af
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/SwiftypeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function search($term = '', $filters = [], $pageNumber = 0, $pageLength =
'auth_token' => $this->getEnv('SS_SWIFTYPE_AUTH_TOKEN'),
'q' => $term,
'document_types' => [$indexName],
'page' => 1 + $pageNumber,
'page' => $pageNumber ?: 1,
'per_page' => $pageLength,
'filters' => [$indexName => $this->translateFilterModifiers($filters)],
'facets' => [$indexName => []],
Expand All @@ -382,9 +382,25 @@ public function search($term = '', $filters = [], $pageNumber = 0, $pageLength =
$response['body'] = $stream->getContents();

$this->response = json_decode($response['body'], true);
$this->response['_total'] = $this->response['record_count'];
$this->response['_total'] = $this->response['info'][$indexName]['total_result_count'];

return new ArrayList($this->response['records'][$indexName]);
$recordData = array_map(
function($item) {
return $this->mapToDataObject($item);
},
$this->response['records'][$indexName]
);

return new ArrayList($recordData);
}

public function mapToDataObject($record)
{
$indices = ArrayList::create(SearchConfig::config()->get('indices'));
$index = $indices->find('name', $this->clientIndexName);
$className = $index['class'];

return Injector::inst()->createWithArgs($className, [$record]);
}

public function getResponse()
Expand Down

0 comments on commit 0f575af

Please sign in to comment.