diff --git a/config/vufind/Primo.ini b/config/vufind/Primo.ini index 6f826a17edb2c74bf16bcf5cad12ec764e9855d4..6823989cbd40cc0fd04c415605783b92602361d7 100644 --- a/config/vufind/Primo.ini +++ b/config/vufind/Primo.ini @@ -130,6 +130,10 @@ top_rows = 2 top_cols = 3 ; Do we want any facets to be collapsed by default? ;collapsedFacets = * +; Should we show "exclude" links for some or all of the facets? Set to * for +; all facets, use a comma-separated list to show for some of the facets, set +; to false or omit to disable "exclude" links +;exclude = * ; These settings affect the way the facets are displayed [Facet_Settings] diff --git a/module/VuFind/src/VuFind/Search/Primo/Params.php b/module/VuFind/src/VuFind/Search/Primo/Params.php index f730978fc243167eb3b9df96e740655c0396a0fb..b5643ebd84c2ec5ecb7a41ebf55e705eab304dd8 100644 --- a/module/VuFind/src/VuFind/Search/Primo/Params.php +++ b/module/VuFind/src/VuFind/Search/Primo/Params.php @@ -71,11 +71,7 @@ class Params extends \VuFind\Search\Base\Params $sort = $this->getSort(); $finalSort = ($sort == 'relevance') ? null : $sort; $backendParams->set('sort', $finalSort); - $filterList = array_merge( - $this->getHiddenFilters(), - $this->filterList - ); - $backendParams->set('filterList', $filterList); + $backendParams->set('filterList', $this->getFilterSettings()); return $backendParams; } @@ -116,4 +112,31 @@ class Params extends \VuFind\Search\Base\Params } return ucwords(str_replace('_', ' ', $str)); } + + /** + * Return the current filters as an array + * + * @return array + */ + public function getFilterSettings() + { + $result = []; + $filterList = array_merge( + $this->getHiddenFilters(), + $this->filterList + ); + foreach ($filterList as $field => $filter) { + $facetOp = 'AND'; + $prefix = substr($field, 0, 1); + if ('~' === $prefix || '-' === $prefix) { + $facetOp = '~' === $prefix ? 'OR' : 'NOT'; + $field = substr($field, 1); + } + $result[$field] = [ + 'facetOp' => $facetOp, + 'values' => $filter + ]; + } + return $result; + } } diff --git a/module/VuFind/src/VuFind/Search/Primo/Results.php b/module/VuFind/src/VuFind/Search/Primo/Results.php index 6565d7100f06ddd3b4598f3d86c636df79b7aa1b..3ebb7b5724427b905a1030d56f5ef0acabb51fcd 100644 --- a/module/VuFind/src/VuFind/Search/Primo/Results.php +++ b/module/VuFind/src/VuFind/Search/Primo/Results.php @@ -100,7 +100,9 @@ class Results extends \VuFind\Search\Base\Results 'displayText' => $displayText, 'isApplied' => $this->getParams()->hasFilter("$field:" . $value), - 'operator' => 'AND', 'count' => $count + 'operator' => + $this->getParams()->getFacetOperator($field), + 'count' => $count ]; } diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php index 56d22647e0c0c7639610e84faf834f4cd3758d7d..fe85b83835960c8a13fd2ed8e1dcaa65a6405a01 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php @@ -284,10 +284,27 @@ class Connector implements \Zend\Log\LoggerAwareInterface // range facet control in the interface. look for injectPubDate if (!empty($args["filterList"])) { foreach ($args["filterList"] as $facet => $values) { - foreach ($values as $value) { - $thisValue = preg_replace('/,/', '+', $value); - $qs[] = "query=facet_" . $facet . ",exact," - . urlencode($thisValue); + $facetOp = 'AND'; + if (isset($values['values'])) { + $facetOp = $values['facetOp']; + $values = $values['values']; + } + array_map( + function ($value) { + return urlencode(preg_replace('/,/', '+', $value)); + }, + $values + ); + if ('OR' === $facetOp) { + $qs[] = "query_inc=facet_$facet,exact," . + implode(',', $values); + } elseif ('NOT' === $facetOp) { + $qs[] = "query_exc=facet_$facet,exact," . + implode(',', $values); + } else { + foreach ($values as $value) { + $qs[] = "query_inc=facet_$facet,exact,$value"; + } } } }