factorize solr results formatting in BookSearch
This commit is contained in:
@@ -51,7 +51,8 @@ class BookSearch
|
||||
/**
|
||||
* @param int $start
|
||||
* @param int $count
|
||||
* @return SolrObject
|
||||
* @return array
|
||||
* @throws WebException
|
||||
*/
|
||||
public function getResults($start = 0, $count = 15)
|
||||
{
|
||||
@@ -64,6 +65,20 @@ class BookSearch
|
||||
$this->query->setStart($start);
|
||||
$this->query->setRows($count);
|
||||
|
||||
return $this->client->query($this->query)->getResponse();
|
||||
try {
|
||||
$results = $this->client->query($this->query)->getResponse();
|
||||
} catch(SolrClientException $e) {
|
||||
throw new WebException ("SolrError", $e->getMessage(), -700);
|
||||
}
|
||||
|
||||
$books = isset($results['response']['docs']) ?
|
||||
array_map(function($o) { return (array) $o; }, $results['response']['docs']) :
|
||||
false;
|
||||
|
||||
return array(
|
||||
'count' => $results['response']['numFound'],
|
||||
'facets' => $results['facet_counts']['facet_fields'],
|
||||
'books' => $books,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user