From f37611abb9ef2b9803b1451a0104e2954a22e585 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 23 Oct 2013 10:22:31 -0400 Subject: [PATCH] Smarter display of range filters. - Resolves VUFIND-922. --- .../VuFind/src/VuFind/Search/Solr/Params.php | 24 +++++++++++++++++++ .../src/VuFind/Search/Summon/Params.php | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php index f0933dfb390..e51db0cc653 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Params.php +++ b/module/VuFind/src/VuFind/Search/Solr/Params.php @@ -492,4 +492,28 @@ class Params extends \VuFind\Search\Base\Params return $backendParams; } + + /** + * Format a single filter for use in getFilterList(). + * + * @param string $field Field name + * @param string $value Field value + * @param string $operator Operator (AND/OR/NOT) + * @param bool $translate Should we translate the label? + * + * @return array + */ + protected function formatFilterListEntry($field, $value, $operator, $translate) + { + $filter = parent::formatFilterListEntry( + $field, $value, $operator, $translate + ); + + // Convert range queries to a language-non-specific format: + if (preg_match('/^\[(.*) TO (.*)\]$/', $value, $matches)) { + $filter['displayText'] = $matches[1] . '-' . $matches[2]; + } + + return $filter; + } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Summon/Params.php b/module/VuFind/src/VuFind/Search/Summon/Params.php index 6f6392c6901..95cfdf41e3b 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Params.php +++ b/module/VuFind/src/VuFind/Search/Summon/Params.php @@ -260,4 +260,28 @@ class Params extends \VuFind\Search\Base\Params } } } + + /** + * Format a single filter for use in getFilterList(). + * + * @param string $field Field name + * @param string $value Field value + * @param string $operator Operator (AND/OR/NOT) + * @param bool $translate Should we translate the label? + * + * @return array + */ + protected function formatFilterListEntry($field, $value, $operator, $translate) + { + $filter = parent::formatFilterListEntry( + $field, $value, $operator, $translate + ); + + // Convert range queries to a language-non-specific format: + if (preg_match('/^\[(.*) TO (.*)\]$/', $value, $matches)) { + $filter['displayText'] = $matches[1] . '-' . $matches[2]; + } + + return $filter; + } } \ No newline at end of file -- GitLab