Skip to content
Snippets Groups Projects
Commit 99c3731e authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

Add exclude and or-facet support to Primo. Expose exclude support. (#1437)

parent a6b0dc44
No related merge requests found
...@@ -130,6 +130,10 @@ top_rows = 2 ...@@ -130,6 +130,10 @@ top_rows = 2
top_cols = 3 top_cols = 3
; Do we want any facets to be collapsed by default? ; Do we want any facets to be collapsed by default?
;collapsedFacets = * ;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 ; These settings affect the way the facets are displayed
[Facet_Settings] [Facet_Settings]
......
...@@ -71,11 +71,7 @@ class Params extends \VuFind\Search\Base\Params ...@@ -71,11 +71,7 @@ class Params extends \VuFind\Search\Base\Params
$sort = $this->getSort(); $sort = $this->getSort();
$finalSort = ($sort == 'relevance') ? null : $sort; $finalSort = ($sort == 'relevance') ? null : $sort;
$backendParams->set('sort', $finalSort); $backendParams->set('sort', $finalSort);
$filterList = array_merge( $backendParams->set('filterList', $this->getFilterSettings());
$this->getHiddenFilters(),
$this->filterList
);
$backendParams->set('filterList', $filterList);
return $backendParams; return $backendParams;
} }
...@@ -116,4 +112,31 @@ class Params extends \VuFind\Search\Base\Params ...@@ -116,4 +112,31 @@ class Params extends \VuFind\Search\Base\Params
} }
return ucwords(str_replace('_', ' ', $str)); 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;
}
} }
...@@ -100,7 +100,9 @@ class Results extends \VuFind\Search\Base\Results ...@@ -100,7 +100,9 @@ class Results extends \VuFind\Search\Base\Results
'displayText' => $displayText, 'displayText' => $displayText,
'isApplied' => 'isApplied' =>
$this->getParams()->hasFilter("$field:" . $value), $this->getParams()->hasFilter("$field:" . $value),
'operator' => 'AND', 'count' => $count 'operator' =>
$this->getParams()->getFacetOperator($field),
'count' => $count
]; ];
} }
......
...@@ -284,10 +284,27 @@ class Connector implements \Zend\Log\LoggerAwareInterface ...@@ -284,10 +284,27 @@ class Connector implements \Zend\Log\LoggerAwareInterface
// range facet control in the interface. look for injectPubDate // range facet control in the interface. look for injectPubDate
if (!empty($args["filterList"])) { if (!empty($args["filterList"])) {
foreach ($args["filterList"] as $facet => $values) { foreach ($args["filterList"] as $facet => $values) {
foreach ($values as $value) { $facetOp = 'AND';
$thisValue = preg_replace('/,/', '+', $value); if (isset($values['values'])) {
$qs[] = "query=facet_" . $facet . ",exact," $facetOp = $values['facetOp'];
. urlencode($thisValue); $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";
}
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment