From d797f62c47f9bded8c4a677cb57b98980f3522c0 Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Mon, 15 Jun 2015 12:12:45 +0200 Subject: [PATCH] - streamlined way of managing query parameters --- Lib/Search/BookSearch.php | 2 +- NetBiblio.php | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Lib/Search/BookSearch.php b/Lib/Search/BookSearch.php index dba008a..105a2bb 100644 --- a/Lib/Search/BookSearch.php +++ b/Lib/Search/BookSearch.php @@ -41,7 +41,7 @@ class BookSearch { if(count($texts) > 0) { $texts = array_map(array('SolrUtils', 'escapeQueryChars'), $texts); - $query = sprintf('%s:(%s)', $field, implode(' OR ', $texts)); + $query = sprintf('%s:("%s")', $field, implode('" OR "', $texts)); $this->addQuery($query, null, false); } } diff --git a/NetBiblio.php b/NetBiblio.php index 90f0f8e..62cb3dd 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -13,7 +13,7 @@ use BSR\Lib\WebService; class NetBiblio extends WebService { /** @var string $version version number */ - public static $version = '1.0.1'; + public static $version = '1.0.2'; private $login = ''; private $client = 'website'; @@ -616,9 +616,10 @@ class NetBiblio extends WebService throw new WebException("CallArg", "Argument must be valid JSON.", -42); } - // The iOS and Android applications still uses 'category' and 'producer' + // shortcuts and the iOS app still uses 'category' $compatibility = array( - 'category' => 'genre', + 'genre' => 'genreCode', + 'category' => 'genreCode', 'producer' => 'producerCode' ); foreach($compatibility as $old => $new) { @@ -645,26 +646,29 @@ class NetBiblio extends WebService $bs->addQuery($queryArray['queryText'], $type); } - if(isset($queryArray['genre']) && is_array($queryArray['genre'])) { - if(($key = array_search('J', $queryArray['genre'])) !== false) { - unset($queryArray['genre']['J']); + if(isset($queryArray['genreCode']) && is_array($queryArray['genreCode'])) { + // Jeunesse is a particular genre with it's own way of being searched + if(($key = array_search('J', $queryArray['genreCode'])) !== false) { + unset($queryArray['genreCode']['J']); $queryArray['jeunesse'] = array('filtrer' => 'filtrer'); } - - $selectedGenres = array_filter($queryArray['genre'], function ($c) { - return $c != '0'; - }); - $bs->addOrQuery($selectedGenres, 'genreCode'); } if(isset($queryArray['jeunesse']) && $queryArray['jeunesse']['filtrer'] === 'filtrer') { $bs->addQuery(1, 'jeunesse'); } - $availableFields = array('producerCode', 'author', 'reader', 'motsMatieres'); + $availableFields = array('producerCode', 'genreCode', 'author', 'reader', 'motsMatieres'); foreach($availableFields as $q) { - if(isset($queryArray[$q]) && strlen($queryArray[$q]) > 0) { - $bs->addQuery($queryArray[$q], $q); + if(isset($queryArray[$q]) && ( + (is_string($queryArray[$q]) && strlen($queryArray[$q]) > 0) || + (is_array($queryArray[$q]) && count($queryArray[$q]) > 0) + )) { + if(is_array($queryArray[$q])) { + $bs->addOrQuery($queryArray[$q], $q); + } else { + $bs->addQuery($queryArray[$q], $q); + } } }