Skip to content
Permalink
Browse files

Add delimited facet capability

  • Loading branch information...
l.osullivan authored and demiankatz committed Feb 3, 2016
1 parent 6f67fc0 commit c5d0de085c44752b9c6d5f747aaeec0eb878801a
@@ -123,6 +123,8 @@ facet_limit = 100 ; how many values should we show for each facet?
; all facets, use a comma-separated list to apply to some of the facets, set
; to false or omit to disable ORed facets.
orFacets = *
; A default delimiter for use with delimited facets (see below).
delimiter = "{{{_:::_}}}"

; The facets listed under the [Advanced] section above will be used as limiters on
; the advanced search screen and will be displayed uniformly as multi-select boxes.
@@ -157,6 +159,20 @@ special_facets = "illustrated,daterange"
;translated_facets[] = building
;translated_facets[] = format

; Any facets named here will be treated as a delimited facet.
; Delimited facets can be used to display a text value for otherwise incomprehensible
; facet values. It can also be used in combination with sorted_by_index (above)
; to fully control the display order of facet values. The delimiter may be present in
; the string an unlimited number of times; only the text after the last delimiter
; will be displayed to the user.
; e.g. facetValue{{{_:::_}}}displayText
; e.g. sortKey{{{_:::_}}}facetValue{{{_:::_}}}displayText
; Per-field delimiters can be set here following a pipe after the facet name.
; e.g. "author_id_str|:::"
; If no delimiter is set, the default delimiter (set above) will be used.
;delimited_facets[] = author_id_str
;delimited_facets[] = "author_id_str|:::"

; These facets will be displayed on the Home Page. If this section is omitted,
; the [Advanced] section will be used instead.
[HomePage]
@@ -141,6 +141,27 @@ abstract class Options implements TranslatorAwareInterface
*/
protected $viewOptions = [];
/**
* Default delimiter used for delimited facets
*
* @var string
*/
protected $defaultFacetDelimiter;
/**
* Facet settings
*
* @var array
*/
protected $delimitedFacets = [];
/**
* Convenient field => delimiter lookup array derived from $delimitedFacets.
*
* @var array
*/
protected $processedDelimitedFacets = null;
/**
* Facet settings
*
@@ -462,6 +483,71 @@ public function getViewOptions()
return $this->viewOptions;
}
/**
* Returns the defaultFacetDelimiter value.
*
* @return string
*/
public function getDefaultFacetDelimiter()
{
return $this->defaultFacetDelimiter;
}
/**
* Set the defaultFacetDelimiter value.
*
* @param string $defaultFacetDelimiter A default delimiter to be used with
* delimited facets
*
* @return void
*/
public function setDefaultFacetDelimiter($defaultFacetDelimiter)
{
$this->defaultFacetDelimiter = $defaultFacetDelimiter;
$this->processedDelimitedFacets = null; // clear processed value cache
}
/**
* Get a list of delimited facets
*
* @param bool $processed False = return raw values; true = process values into
* field => delimiter associative array.
*
* @return array
*/
public function getDelimitedFacets($processed = false)
{
if (!$processed) {
return $this->delimitedFacets;
}
if (null === $this->processedDelimitedFacets) {
$this->processedDelimitedFacets = [];
$defaultDelimiter = $this->getDefaultFacetDelimiter();
foreach ($this->delimitedFacets as $current) {
$parts = explode('|', $current, 2);
if (count($parts) == 2) {
$this->processedDelimitedFacets[$parts[0]] = $parts[1];
} else {
$this->processedDelimitedFacets[$parts[0]] = $defaultDelimiter;
}
}
}
return $this->processedDelimitedFacets;
}
/**
* Set the delimitedFacets value.
*
* @param array $delimitedFacets An array of delimited facet names
*
* @return void
*/
public function setDelimitedFacets($delimitedFacets)
{
$this->delimitedFacets = $delimitedFacets;
$this->processedDelimitedFacets = null; // clear processed value cache
}
/**
* Get a list of facets that are subject to translation.
*
@@ -946,6 +946,26 @@ public function getFilterList($excludeCheckboxFilters = false)
return $list;
}
/**
* Check for delimited facets -- if $field is a delimited facet field,
* process $displayText accordingly. Return the appropriate display value.
*
* @param string $field The facet
* @param string $displayText The facet value
*
* @return string
*/
public function checkForDelimitedFacetDisplayText($field, $displayText)
{
$delimitedFacetFields = $this->getOptions()->getDelimitedFacets(true);
if (isset($delimitedFacetFields[$field])) {
$parts = explode($delimitedFacetFields[$field], $displayText);
$displayText = end($parts);
}
return $displayText;
}
/**
* Format a single filter for use in getFilterList().
*
@@ -958,12 +978,13 @@ public function getFilterList($excludeCheckboxFilters = false)
*/
protected function formatFilterListEntry($field, $value, $operator, $translate)
{
$displayText = $this->checkForDelimitedFacetDisplayText($field, $value);
if ($translate) {
$domain = $this->getOptions()->getTextDomainForTranslatedFacet($field);
$displayText = $this->translate("$domain::$value");
} else {
$displayText = $value;
$displayText = $this->translate("$domain::$displayText");
}
return compact('value', 'displayText', 'field', 'operator');
}
@@ -152,6 +152,18 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
$facetSettings->Advanced_Settings->translated_facets->toArray()
);
}
if (isset($facetSettings->Advanced_Settings->delimiter)) {
$this->setDefaultFacetDelimiter(
$facetSettings->Advanced_Settings->delimiter
);
}
if (isset($facetSettings->Advanced_Settings->delimited_facets)
&& count($facetSettings->Advanced_Settings->delimited_facets) > 0
) {
$this->setDelimitedFacets(
$facetSettings->Advanced_Settings->delimited_facets->toArray()
);
}
if (isset($facetSettings->Advanced_Settings->special_facets)) {
$this->specialAdvancedFacets
= $facetSettings->Advanced_Settings->special_facets;
@@ -263,9 +263,13 @@ public function getFacetList($filter = null)
// Initialize the array of data about the current facet:
$currentSettings = [];
$currentSettings['value'] = $value;
$currentSettings['displayText']
= $translate
? $this->translate("$translateTextDomain::$value") : $value;
$displayText = $this->getParams()
->checkForDelimitedFacetDisplayText($field, $value);
$currentSettings['displayText'] = $translate
? $this->translate("$translateTextDomain::$displayText")
: $displayText;
$currentSettings['count'] = $count;
$currentSettings['operator']
= $this->getParams()->getFacetOperator($field);

0 comments on commit c5d0de0

Please sign in to comment.
You can’t perform that action at this time.