work on search: doc, bug fix, factorisation

This commit is contained in:
Gilles Crettenand
2015-06-03 13:39:34 +02:00
parent c303f4e91c
commit 6d97b2047f
2 changed files with 43 additions and 16 deletions

View File

@@ -540,7 +540,23 @@ class NetBiblio extends WebService
* This method is used by the website and the Android application to perform
* book search.
*
* TODO: describe various options for the parameters
* Search parameters :
*
* ° queryText : the text to search for
* ° queryType : the field to search in, defaults to 'text'
*
* ° genre : array of 'genreCode' to search for
* ° jeunesse : only display books for kids (must have format 'jeunesse' => array('filtrer' => 'filtrer')
* ° producerCode : filter by 'producerCode'
* ° reader : filter by 'reader'
*
* ° count : number of results we want
* ° page : page to start at (0 is the first)
*
* Deprecated, but still in use on mobile apps :
*
* ° category : synonym for 'genre' (see above)
* ° producer : synonym for 'producerCode' (see above)
*
* @param string $values JSON encoded object
* @return array
@@ -555,10 +571,16 @@ class NetBiblio extends WebService
throw new WebException("CallArg", "Argument must be valid JSON.", -42);
}
// The iOS and Android applications still uses 'category' instead of 'genre'
if(isset($queryArray['category']) && is_array($queryArray['category'])) {
$queryArray['genre'] = $queryArray['category'];
unset($queryArray['category']);
// The iOS and Android applications still uses 'category' and 'producer'
$compatibility = array(
'category' => 'genre',
'producer' => 'producerCode'
);
foreach($compatibility as $old => $new) {
if(isset($queryArray[$old])) {
$queryArray[$new] = $queryArray[$old];
unset($queryArray[$old]);
}
}
$bs = new BookSearch();
@@ -589,21 +611,18 @@ class NetBiblio extends WebService
$selectedGenres = array_filter($queryArray['genre'], function ($c) {
return $c != '0';
});
if (count($selectedGenres) > 0) {
$selectedGenres = array_map(function ($c) {
return 'genreCode:'.\SolrUtils::escapeQueryChars($c);
}, $selectedGenres);
$bs->addQuery('('.implode(' OR ', $selectedGenres).')', null, false);
}
$bs->addOrQuery($selectedGenres, 'genreCode');
}
if(isset($queryArray['jeunesse']) && $queryArray['jeunesse']['filtrer'] === 'filtrer') {
$bs->addQuery(1, 'jeunesse');
}
// The following query filter is used by the mobile applications
if(isset($queryArray['producer']) && strlen($queryArray['producer']) > 0) {
$bs->addQuery($queryArray['producer'], 'producerCode');
$queries = array('producerCode', 'reader');
foreach($queries as $q) {
if(isset($queryArray[$q]) && strlen($queryArray[$q]) > 0) {
$bs->addQuery($queryArray[$q], $q);
}
}
$count = isset($queryArray['count']) ? (int) $queryArray['count'] : Configuration::get('solr.result_count');