diff --git a/config/vufind/Summon.ini b/config/vufind/Summon.ini index 1020a27546e94aaf89a5a22c4bf3d64c47720e6c..f50757c17dd709b96c14ff6907f869c6ad4853a1 100644 --- a/config/vufind/Summon.ini +++ b/config/vufind/Summon.ini @@ -111,6 +111,10 @@ top_cols = 3 ; all facets, use a comma-separated list to show for some of the facets, set ; to false or omit to disable "exclude" links ;exclude = * +; Should we OR together facets rather than ANDing them? Set to * for +; all facets, use a comma-separated list to apply to some of the facets, set +; to false or omit to disable ORed facets. +;orFacets = * ; These settings affect the way the facets are displayed [Facet_Settings] diff --git a/config/vufind/facets.ini b/config/vufind/facets.ini index f4118677fe7bf0a497285f902798330710c22360..94076851eb705ec622338468c074d40e5f3c22eb 100644 --- a/config/vufind/facets.ini +++ b/config/vufind/facets.ini @@ -51,6 +51,10 @@ top_cols = 3 ; all facets, use a comma-separated list to show for some of the facets, set ; to false or omit to disable "exclude" links ;exclude = * +; Should we OR together facets rather than ANDing them? Set to * for +; all facets, use a comma-separated list to apply to some of the facets, set +; to false or omit to disable ORed facets. +;orFacets = * ; The author home screen has different facets [Author] diff --git a/module/VuFind/src/VuFind/Recommend/SideFacets.php b/module/VuFind/src/VuFind/Recommend/SideFacets.php index d325199bf09416461cf861a6c0bfc009a41a999a..aa6c005ecb9c9a0f41032e9857cfd698f437a3e9 100644 --- a/module/VuFind/src/VuFind/Recommend/SideFacets.php +++ b/module/VuFind/src/VuFind/Recommend/SideFacets.php @@ -62,6 +62,13 @@ class SideFacets implements RecommendInterface */ protected $excludableFacets = array(); + /** + * Facets that are "ORed" instead of "ANDed." + * + * @var array + */ + protected $orFacets = array(); + /** * Checkbox facet configuration * @@ -128,6 +135,17 @@ class SideFacets implements RecommendInterface } } + // Which facets are ORed? + if (isset($config->Results_Settings->orFacets)) { + if ($config->Results_Settings->orFacets === '*') { + $this->orFacets = array_keys($this->mainFacets); + } else { + $this->orFacets = array_map( + 'trim', explode(',', $config->Results_Settings->orFacets) + ); + } + } + // Get a list of fields that should be displayed as date ranges rather than // standard facet lists. if (isset($config->SpecialFacets->dateRange)) { @@ -165,7 +183,7 @@ class SideFacets implements RecommendInterface { // Turn on side facets in the search results: foreach ($this->mainFacets as $name => $desc) { - $params->addFacet($name, $desc); + $params->addFacet($name, $desc, in_array($name, $this->orFacets)); } foreach ($this->checkboxFacets as $name => $desc) { $params->addCheckboxFacet($name, $desc); diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php index beb53f61d736ca57f2496392c6ee912f7d8fc8c4..f0933dfb3902eb82c461df357bad79763f8fb3f5 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Params.php +++ b/module/VuFind/src/VuFind/Search/Solr/Params.php @@ -119,7 +119,8 @@ class Params extends \VuFind\Search\Base\Params } } foreach ($orFilters as $field => $parts) { - $filterQuery[] = $field . ':(' . implode(' OR ', $parts) . ')'; + $filterQuery[] = '{!tag=' . $field . '_filter}' . $field + . ':(' . implode(' OR ', $parts) . ')'; } return $filterQuery; } @@ -136,6 +137,9 @@ class Params extends \VuFind\Search\Base\Params if (!empty($this->facetConfig)) { $facetSet['limit'] = $this->facetLimit; foreach ($this->facetConfig as $facetField => $facetName) { + if ($this->getFacetOperator($facetField) == 'OR') { + $facetField = '{!ex=' . $facetField . '_filter}' . $facetField; + } $facetSet['field'][] = $facetField; } if ($this->facetOffset != null) { @@ -288,17 +292,8 @@ class Params extends \VuFind\Search\Base\Params */ public function initBasicFacets() { - $config = $this->getServiceLocator()->get('VuFind\Config')->get('facets'); - if (isset($config->ResultsTop)) { - foreach ($config->ResultsTop as $key => $value) { - $this->addFacet($key, $value); - } - } - if (isset($config->Results)) { - foreach ($config->Results as $key => $value) { - $this->addFacet($key, $value); - } - } + $this->initFacetList('ResultsTop', 'Results_Settings'); + $this->initFacetList('Results', 'Results_Settings'); } /** diff --git a/module/VuFind/src/VuFind/Search/Summon/Params.php b/module/VuFind/src/VuFind/Search/Summon/Params.php index 7a8b9969206b943efe9f8e45ee734be5486fa8d7..6f6392c6901aca210acf37e8ae0d7b215bc51400 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Params.php +++ b/module/VuFind/src/VuFind/Search/Summon/Params.php @@ -191,7 +191,8 @@ class Params extends \VuFind\Search\Base\Params // if not, override them with defaults. $parts = explode(',', $facet); $facetName = $parts[0]; - $facetMode = isset($parts[1]) ? $parts[1] : 'and'; + $defaultMode = ($this->getFacetOperator($facet) == 'OR') ? 'or' : 'and'; + $facetMode = isset($parts[1]) ? $parts[1] : $defaultMode; $facetPage = isset($parts[2]) ? $parts[2] : 1; $facetLimit = isset($parts[3]) ? $parts[3] : $defaultFacetLimit; $facetParams = "{$facetMode},{$facetPage},{$facetLimit}"; diff --git a/module/VuFind/src/VuFind/Search/UrlQueryHelper.php b/module/VuFind/src/VuFind/Search/UrlQueryHelper.php index 275bdb97cc5f0ee81c98888629faa59dde520a2b..dd119ec51743f64d3faa4f23d05dc7726ecccd17 100644 --- a/module/VuFind/src/VuFind/Search/UrlQueryHelper.php +++ b/module/VuFind/src/VuFind/Search/UrlQueryHelper.php @@ -242,7 +242,7 @@ class UrlQueryHelper public function addFacet($field, $value, $operator = 'AND') { // Facets are just a special case of filters: - $prefix = ($operator == 'NOT') ? '-' : ''; + $prefix = ($operator == 'NOT') ? '-' : ($operator == 'OR' ? '~' : ''); return $this->addFilter($prefix . $field . ':"' . $value . '"'); } diff --git a/themes/blueprint/templates/Recommend/SideFacets.phtml b/themes/blueprint/templates/Recommend/SideFacets.phtml index 5eeb7962fd1fd0e7f1c327135e84659a6b189b7e..2755db07470492f5f479c68df529ca0fe6f86e41 100644 --- a/themes/blueprint/templates/Recommend/SideFacets.phtml +++ b/themes/blueprint/templates/Recommend/SideFacets.phtml @@ -66,7 +66,7 @@ <dd><?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="Selected"/></dd> <? else: ?> <dd> - <a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>) + <a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'], $thisFacet['operator'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>) <? if ($allowExclude): ?> <a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'], 'NOT')?>"><?=$this->transEsc('exclude_facet')?></a> <? endif; ?> diff --git a/themes/jquerymobile/templates/Recommend/SideFacets-dialog.phtml b/themes/jquerymobile/templates/Recommend/SideFacets-dialog.phtml index 9247bc0ee419816a6c8fe89bc60056817919f261..447c9458c26ece4618378efcdf9240624eb5acf5 100644 --- a/themes/jquerymobile/templates/Recommend/SideFacets-dialog.phtml +++ b/themes/jquerymobile/templates/Recommend/SideFacets-dialog.phtml @@ -18,7 +18,7 @@ <? if ($thisFacet['isApplied']): ?> <li data-icon="check" class="checked"><a href="" data-rel="back"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li> <? else: ?> - <li><a rel="external" href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li> + <li><a rel="external" href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'], $thisFacet['operator'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li> <? endif; ?> <? endforeach; ?> </ul>