From c20d58bd71dd09a9c869525f67c31ad8b7158e45 Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Fri, 12 Jun 2015 10:49:01 +0200 Subject: [PATCH] Fix search for iOS : - text does not exists anymore as a field - better detection of book codes --- NetBiblio.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/NetBiblio.php b/NetBiblio.php index 9c4b306..bb7f18e 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -228,6 +228,15 @@ class NetBiblio extends WebService return $books; } + /** + * Return true if the value matches a book code (a number with 1 to 5 digits) + * @param $val + * @return int + */ + protected function IsBookCode($val) { + return preg_match('/^[0-9]{1,5}$/', $val); + } + // ********************************** // * Public methods * // ********************************** @@ -530,20 +539,24 @@ class NetBiblio extends WebService * If a number is given, search in the book codes, otherwise perform * a full text search. * - * @param string $query Text to search + * @param string $text Text to search * @param int $start * @param int $limit * @return array an array of books * @throws WebException */ - public function Search($query, $start, $limit) + public function Search($text, $start, $limit) { $query = array( - 'queryText' => $query, - 'queryType' => is_numeric($query) && strlen($query) <= 5 ? 'code' : 'text', + 'queryText' => $text, 'count' => $limit, 'page' => max(intval($start) - 1, 0), ); + + if($this->IsBookCode($text)) { + $query['queryType'] = 'code'; + } + $data = $this->NewSearch(json_encode($query)); // remove fields that are not used in "old" search