From 6abf00985dab1ec43dc7898cfc506a264afbd641 Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Mon, 1 Jun 2015 15:13:53 +0200 Subject: [PATCH] use Solr for random books --- mobile.netbiblio.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mobile.netbiblio.php b/mobile.netbiblio.php index ebfe333..eb0aa5a 100644 --- a/mobile.netbiblio.php +++ b/mobile.netbiblio.php @@ -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)