use 'OR' only for genres

master
Gilles Crettenand 11 years ago
parent c872c7b9bc
commit 5ebe300c28

@ -45,15 +45,25 @@ class BookSearch
*/ */
} }
public function addOrQuery(array $texts, $field) public function addCompoundQuery(array $texts, $field, $operator)
{ {
if(count($texts) > 0) { if(count($texts) > 0) {
$texts = array_map(array('SolrUtils', 'escapeQueryChars'), $texts); $texts = array_map(array('SolrUtils', 'escapeQueryChars'), $texts);
$query = sprintf('%s:("%s")', $field, implode('" OR "', $texts)); $query = sprintf('%s:("%s")', $field, implode('" '.$operator.'"', $texts));
$this->addQuery($query, null, false); $this->addQuery($query, null, false);
} }
} }
public function addOrQuery(array $texts, $field)
{
$this->addCompoundQuery($texts, $field, 'OR');
}
public function addAndQuery(array $texts, $field)
{
$this->addCompoundQuery($texts, $field, 'AND');
}
public function addQuery($queryText, $queryField = null, $escape = true) public function addQuery($queryText, $queryField = null, $escape = true)
{ {
if($escape) { if($escape) {

@ -13,7 +13,7 @@ use BSR\Lib\WebService;
class NetBiblio extends WebService class NetBiblio extends WebService
{ {
/** @var string $version version number */ /** @var string $version version number */
public static $version = '1.0.5'; public static $version = '1.0.6';
private $login = ''; private $login = '';
private $client = 'website'; private $client = 'website';
@ -688,7 +688,8 @@ class NetBiblio extends WebService
(is_array($queryArray[$q]) && count($queryArray[$q]) > 0) (is_array($queryArray[$q]) && count($queryArray[$q]) > 0)
)) { )) {
if(is_array($queryArray[$q])) { if(is_array($queryArray[$q])) {
$bs->addOrQuery($queryArray[$q], $q); // Genres cannot overlap, so we use 'OR', otherwise use 'AND'
$bs->addCompoundQuery($queryArray[$q], $q, $q == 'genreCode' ? 'OR' : 'AND');
} else { } else {
$bs->addQuery($queryArray[$q], $q); $bs->addQuery($queryArray[$q], $q);
} }

Loading…
Cancel
Save