Skip to content
Snippets Groups Projects
Commit de0620eb authored by Demian Katz's avatar Demian Katz
Browse files

Added ORed facet support to SideFacets.

- Progress on VUFIND-177
- Thanks to Daniel Aineah and Tuan Nguyen for Solr development work
parent d757db4a
No related merge requests found
...@@ -111,6 +111,10 @@ top_cols = 3 ...@@ -111,6 +111,10 @@ top_cols = 3
; all facets, use a comma-separated list to show for some of the facets, set ; all facets, use a comma-separated list to show for some of the facets, set
; to false or omit to disable "exclude" links ; to false or omit to disable "exclude" links
;exclude = * ;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 ; These settings affect the way the facets are displayed
[Facet_Settings] [Facet_Settings]
......
...@@ -51,6 +51,10 @@ top_cols = 3 ...@@ -51,6 +51,10 @@ top_cols = 3
; all facets, use a comma-separated list to show for some of the facets, set ; all facets, use a comma-separated list to show for some of the facets, set
; to false or omit to disable "exclude" links ; to false or omit to disable "exclude" links
;exclude = * ;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 ; The author home screen has different facets
[Author] [Author]
......
...@@ -62,6 +62,13 @@ class SideFacets implements RecommendInterface ...@@ -62,6 +62,13 @@ class SideFacets implements RecommendInterface
*/ */
protected $excludableFacets = array(); protected $excludableFacets = array();
/**
* Facets that are "ORed" instead of "ANDed."
*
* @var array
*/
protected $orFacets = array();
/** /**
* Checkbox facet configuration * Checkbox facet configuration
* *
...@@ -128,6 +135,17 @@ class SideFacets implements RecommendInterface ...@@ -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 // Get a list of fields that should be displayed as date ranges rather than
// standard facet lists. // standard facet lists.
if (isset($config->SpecialFacets->dateRange)) { if (isset($config->SpecialFacets->dateRange)) {
...@@ -165,7 +183,7 @@ class SideFacets implements RecommendInterface ...@@ -165,7 +183,7 @@ class SideFacets implements RecommendInterface
{ {
// Turn on side facets in the search results: // Turn on side facets in the search results:
foreach ($this->mainFacets as $name => $desc) { 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) { foreach ($this->checkboxFacets as $name => $desc) {
$params->addCheckboxFacet($name, $desc); $params->addCheckboxFacet($name, $desc);
......
...@@ -119,7 +119,8 @@ class Params extends \VuFind\Search\Base\Params ...@@ -119,7 +119,8 @@ class Params extends \VuFind\Search\Base\Params
} }
} }
foreach ($orFilters as $field => $parts) { foreach ($orFilters as $field => $parts) {
$filterQuery[] = $field . ':(' . implode(' OR ', $parts) . ')'; $filterQuery[] = '{!tag=' . $field . '_filter}' . $field
. ':(' . implode(' OR ', $parts) . ')';
} }
return $filterQuery; return $filterQuery;
} }
...@@ -136,6 +137,9 @@ class Params extends \VuFind\Search\Base\Params ...@@ -136,6 +137,9 @@ class Params extends \VuFind\Search\Base\Params
if (!empty($this->facetConfig)) { if (!empty($this->facetConfig)) {
$facetSet['limit'] = $this->facetLimit; $facetSet['limit'] = $this->facetLimit;
foreach ($this->facetConfig as $facetField => $facetName) { foreach ($this->facetConfig as $facetField => $facetName) {
if ($this->getFacetOperator($facetField) == 'OR') {
$facetField = '{!ex=' . $facetField . '_filter}' . $facetField;
}
$facetSet['field'][] = $facetField; $facetSet['field'][] = $facetField;
} }
if ($this->facetOffset != null) { if ($this->facetOffset != null) {
...@@ -288,17 +292,8 @@ class Params extends \VuFind\Search\Base\Params ...@@ -288,17 +292,8 @@ class Params extends \VuFind\Search\Base\Params
*/ */
public function initBasicFacets() public function initBasicFacets()
{ {
$config = $this->getServiceLocator()->get('VuFind\Config')->get('facets'); $this->initFacetList('ResultsTop', 'Results_Settings');
if (isset($config->ResultsTop)) { $this->initFacetList('Results', 'Results_Settings');
foreach ($config->ResultsTop as $key => $value) {
$this->addFacet($key, $value);
}
}
if (isset($config->Results)) {
foreach ($config->Results as $key => $value) {
$this->addFacet($key, $value);
}
}
} }
/** /**
......
...@@ -191,7 +191,8 @@ class Params extends \VuFind\Search\Base\Params ...@@ -191,7 +191,8 @@ class Params extends \VuFind\Search\Base\Params
// if not, override them with defaults. // if not, override them with defaults.
$parts = explode(',', $facet); $parts = explode(',', $facet);
$facetName = $parts[0]; $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; $facetPage = isset($parts[2]) ? $parts[2] : 1;
$facetLimit = isset($parts[3]) ? $parts[3] : $defaultFacetLimit; $facetLimit = isset($parts[3]) ? $parts[3] : $defaultFacetLimit;
$facetParams = "{$facetMode},{$facetPage},{$facetLimit}"; $facetParams = "{$facetMode},{$facetPage},{$facetLimit}";
......
...@@ -242,7 +242,7 @@ class UrlQueryHelper ...@@ -242,7 +242,7 @@ class UrlQueryHelper
public function addFacet($field, $value, $operator = 'AND') public function addFacet($field, $value, $operator = 'AND')
{ {
// Facets are just a special case of filters: // Facets are just a special case of filters:
$prefix = ($operator == 'NOT') ? '-' : ''; $prefix = ($operator == 'NOT') ? '-' : ($operator == 'OR' ? '~' : '');
return $this->addFilter($prefix . $field . ':"' . $value . '"'); return $this->addFilter($prefix . $field . ':"' . $value . '"');
} }
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<dd><?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="Selected"/></dd> <dd><?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="Selected"/></dd>
<? else: ?> <? else: ?>
<dd> <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): ?> <? if ($allowExclude): ?>
<a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'], 'NOT')?>"><?=$this->transEsc('exclude_facet')?></a> <a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'], 'NOT')?>"><?=$this->transEsc('exclude_facet')?></a>
<? endif; ?> <? endif; ?>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<? if ($thisFacet['isApplied']): ?> <? 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> <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: ?> <? 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; ?> <? endif; ?>
<? endforeach; ?> <? endforeach; ?>
</ul> </ul>
......
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