Fix search for iOS :

- text does not exists anymore as a field
- better detection of book codes
master
Gilles Crettenand 11 years ago
parent 0143374ae1
commit c20d58bd71

@ -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

Loading…
Cancel
Save