factorize solr results formatting in BookSearch

This commit is contained in:
Gilles Crettenand
2015-06-01 15:20:01 +02:00
parent 6abf00985d
commit 7b2c4c18ee
2 changed files with 23 additions and 20 deletions

View File

@@ -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,
);
}
}