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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,12 +357,7 @@ class NetBiblio extends WebService
|
||||
$bs = new BookSearch();
|
||||
$bs->addSortField('random_'.$seed);
|
||||
$results = $bs->getResults(0, $number);
|
||||
|
||||
if($results['response']['docs']) {
|
||||
$books = array_map(function($o) { return (array) $o; }, $results['response']['docs']);
|
||||
return $this->AddBookData($books);
|
||||
}
|
||||
return array();
|
||||
return $results['books'] ? $this->AddBookData($results['books']) : array();
|
||||
}
|
||||
|
||||
public function Search($query, $start, $limit)
|
||||
@@ -444,21 +439,14 @@ class NetBiblio extends WebService
|
||||
$count = isset($queryArray['count']) ? (int) $queryArray['count'] : Configuration::get('solr.result_count');
|
||||
$start = isset($queryArray['page']) ? $queryArray['page'] * $count : 0;
|
||||
|
||||
try {
|
||||
$results = $bs->getResults($start, $count);
|
||||
} catch(SolrClientException $e) {
|
||||
throw new WebException ("SolrError", $e->getMessage(), -700);
|
||||
}
|
||||
|
||||
$results = $bs->getResults($start, $count);
|
||||
$data = array(
|
||||
'count' => $results['response']['numFound'],
|
||||
'facets' => $results['facet_counts']['facet_fields'],
|
||||
'count' => $results['count'],
|
||||
'facets' => $results['facets'],
|
||||
);
|
||||
|
||||
if($results['response']['docs']) {
|
||||
$books = array_map(function($o) { return (array) $o; }, $results['response']['docs']);
|
||||
$books = $this->AddBookData($books);
|
||||
$data = array_merge($data, $books);
|
||||
if($results['books']) {
|
||||
$data = array_merge($data, $this->AddBookData($results['books']));
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user