From e9171090383a407a46f228010b2d147ff27b69cc Mon Sep 17 00:00:00 2001 From: edelm <matthias.edel@unibas.ch> Date: Tue, 4 Jun 2019 21:23:24 +0200 Subject: [PATCH] Improve Autocomplete configuration (#1374) - Refactor autocomplete configuration loading to reduce redundancy. - Improve documentation of autocomplete options in .ini files. - Add missing configuration support for Summon. --- config/vufind/Summon.ini | 17 +++++++++++++++++ config/vufind/searches.ini | 5 +++++ .../VuFind/src/VuFind/Search/Base/Options.php | 17 +++++++++++++++++ module/VuFind/src/VuFind/Search/EDS/Options.php | 11 +++-------- .../VuFind/src/VuFind/Search/Solr/Options.php | 8 +------- .../VuFind/src/VuFind/Search/Summon/Options.php | 3 +++ .../VuFind/src/VuFind/Search/Tags/Options.php | 6 ++---- 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/config/vufind/Summon.ini b/config/vufind/Summon.ini index 2f0820ac626..26d25143dfb 100644 --- a/config/vufind/Summon.ini +++ b/config/vufind/Summon.ini @@ -338,3 +338,20 @@ next_prev_navigation = false ; regular Syndetics if necessary. [List] view=full + +; This section controls the behavior of the Autocomplete within Summon. +[Autocomplete] +; Disabled by default. +enabled = false + +; Define a default_handler +default_handler = None + +; Auto-submit autocomplete on click or enter +auto_submit = true + +; In this section, set the key equal to a search type from [Basic_Searches] and +; the value equal to an autocomplete handler in order to customize autocompletion +; behavior when that search type is selected. See searches.ini for a list of +; available handlers. +[Autocomplete_Types] diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index 531cd8bfabc..45ac7dda100 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -476,6 +476,11 @@ sort = "last_indexed desc" ; ; The available autocomplete handlers are: ; +; Eds:[Mode] +; Use the EBSCO Discovery Service autocomplete handler (only intended to be +; used in the context of the EDS backend). [Mode] can be either "holdings" for +; title completion in PubFinder or "rawqueries" for completion of basic textual +; queries. ; None ; Do not provide any suggestions. You should use this handler if you want to ; disable suggestions for one search type while still providing suggestions diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php index 882024b6624..f3c8d1cfebf 100644 --- a/module/VuFind/src/VuFind/Search/Base/Options.php +++ b/module/VuFind/src/VuFind/Search/Base/Options.php @@ -28,6 +28,7 @@ namespace VuFind\Search\Base; use VuFind\I18n\Translator\TranslatorAwareInterface; +use Zend\Config\Config; /** * Abstract options search model. @@ -938,4 +939,20 @@ abstract class Options implements TranslatorAwareInterface { return $this->firstlastNavigation; } + + /** + * Configure autocomplete preferences from an .ini file. + * + * @param Config $searchSettings Object representation of .ini file + * + * @return void + */ + protected function configureAutocomplete(Config $searchSettings) + { + // Only change settings from current values if they are defined in .ini: + $this->autocompleteEnabled = $searchSettings->Autocomplete->enabled + ?? $this->autocompleteEnabled; + $this->autocompleteAutoSubmit = $searchSettings->Autocomplete->auto_submit + ?? $this->autocompleteAutoSubmit; + } } diff --git a/module/VuFind/src/VuFind/Search/EDS/Options.php b/module/VuFind/src/VuFind/Search/EDS/Options.php index 5756231ac6b..2fa20504888 100644 --- a/module/VuFind/src/VuFind/Search/EDS/Options.php +++ b/module/VuFind/src/VuFind/Search/EDS/Options.php @@ -137,14 +137,6 @@ class Options extends \VuFind\Search\Base\Options $facetConf->Advanced_Facet_Settings->translated_facets->toArray() ); } - // Load autocomplete preferences: - if (isset($searchSettings->Autocomplete->enabled)) { - $this->autocompleteEnabled = $searchSettings->Autocomplete->enabled; - } - if (isset($searchSettings->Autocomplete->auto_submit)) { - $this->autocompleteAutoSubmit - = $searchSettings->Autocomplete->auto_submit; - } } /** @@ -406,6 +398,9 @@ class Options extends \VuFind\Search\Base\Options $this->setCommonSettings( $searchSettings, 'common_expanders', 'expanderOptions', 'commonExpanders' ); + + // Load autocomplete preferences: + $this->configureAutocomplete($searchSettings); } /** diff --git a/module/VuFind/src/VuFind/Search/Solr/Options.php b/module/VuFind/src/VuFind/Search/Solr/Options.php index 1a1bfc43f27..d15add0c4e2 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Options.php +++ b/module/VuFind/src/VuFind/Search/Solr/Options.php @@ -209,13 +209,7 @@ class Options extends \VuFind\Search\Base\Options } // Load autocomplete preferences: - if (isset($searchSettings->Autocomplete->enabled)) { - $this->autocompleteEnabled = $searchSettings->Autocomplete->enabled; - } - if (isset($searchSettings->Autocomplete->auto_submit)) { - $this->autocompleteAutoSubmit - = $searchSettings->Autocomplete->auto_submit; - } + $this->configureAutocomplete($searchSettings); // Load shard settings if (isset($searchSettings->IndexShards) diff --git a/module/VuFind/src/VuFind/Search/Summon/Options.php b/module/VuFind/src/VuFind/Search/Summon/Options.php index ac5fb409c1c..ce8f8888d0d 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Options.php +++ b/module/VuFind/src/VuFind/Search/Summon/Options.php @@ -147,6 +147,9 @@ class Options extends \VuFind\Search\Base\Options = $searchSettings->General->empty_search_relevance_override; } + // Load autocomplete preferences: + $this->configureAutocomplete($searchSettings); + // Set up views $this->initViewOptions($searchSettings); diff --git a/module/VuFind/src/VuFind/Search/Tags/Options.php b/module/VuFind/src/VuFind/Search/Tags/Options.php index 05dcca63767..8ad292ccdd3 100644 --- a/module/VuFind/src/VuFind/Search/Tags/Options.php +++ b/module/VuFind/src/VuFind/Search/Tags/Options.php @@ -75,10 +75,8 @@ class Options extends \VuFind\Search\Base\Options 'title' => 'sort_title', 'author' => 'sort_author', 'year DESC' => 'sort_year', 'year' => 'sort_year asc' ]; - // Load autocomplete preference: - if (isset($searchSettings->Autocomplete->enabled)) { - $this->autocompleteEnabled = $searchSettings->Autocomplete->enabled; - } + // Load autocomplete preferences: + $this->configureAutocomplete($searchSettings); } /** -- GitLab