use Solr for random books

master
Gilles Crettenand 11 years ago
parent d15f4f58e7
commit 6abf00985d

@ -349,22 +349,20 @@ class NetBiblio extends WebService
return $this->AddBookData($book);
}
public function GetRandomBooks($number = 100) {
$sql = "SELECT TOP $number NoticeId
FROM Notices
WHERE
(
Notices.MediaType1Code='CDD' OR
Notices.MediaType1Code='CDA' OR
Notices.MediaType1Code='CDS'
)
AND Notices.Visible=1
AND Notices.[NoticeNr] NOT LIKE '%%~%%'
ORDER BY NEWID();";
$ids = Connection::execute($sql)->to_array();
$ids = array_map(function($a) { return $a['NoticeId']; }, $ids);
$books = AudioBook::findBy('NoticeId', $ids, true);
return array_values($this->AddBookData($books));
public function GetRandomBooks($number = 100, $seed = null) {
if(is_null($seed)) {
$seed = time();
}
$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();
}
public function Search($query, $start, $limit)

Loading…
Cancel
Save