diff --git a/config/vufind/Search2.ini b/config/vufind/Search2.ini index 5d18744c7a48ef3b3f9a8fe71fcdf65ca947ce2f..ffb9b5374ca1aa1d268cee35bd1a58708dc3f628 100644 --- a/config/vufind/Search2.ini +++ b/config/vufind/Search2.ini @@ -188,6 +188,11 @@ view=full ;content[] = IlsStatusMonitor content[] = FacetList:Search2 +[API] +;recordAccessPermission = access.api.Record +;searchAccessPermission = access.api.Search +;maxLimit = 100 + ; ---------- facets.ini settings ---------- [Results] diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index 4ee8c8899bd0debd617fd39a822f930031584dd9..0628b828e68284a4cafd497d86f2f9380c1f6be3 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -733,3 +733,12 @@ view=full ; and that version would be loaded when the user's language was set to German. content[] = IlsStatusMonitor content[] = FacetList + +; This section controls default behavior of the Search API. +[API] +; These permissions must be defined in permissions.ini to grant access to the API: +recordAccessPermission = access.api.Record +searchAccessPermission = access.api.Search + +; This is the maximum number of results that can be returned in a single response: +maxLimit = 100 diff --git a/config/vufind/website.ini b/config/vufind/website.ini index 292764405e694f2521c7cb3dfebeb24f2769fe30..c2972f29b3b8c6846c1f7a38ec372f09fda38405 100644 --- a/config/vufind/website.ini +++ b/config/vufind/website.ini @@ -46,3 +46,10 @@ facet_limit = 30 ;[Index] ;url = http://localhost:8983/solr ;default_core = website + +; This section controls default behavior of the Web Search API. Settings omitted +; here will be inherited from searches.ini; see that file for more details. +[API] +;recordAccessPermission = access.api.Record +;searchAccessPermission = access.api.Search +;maxLimit = 100 diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php index 1a65680c03df625b02a8c4f20f3229e3573e5da5..63deb18fc9054a177c1fda795d2a77f15492ee2f 100644 --- a/module/VuFind/src/VuFind/Search/Base/Options.php +++ b/module/VuFind/src/VuFind/Search/Base/Options.php @@ -885,6 +885,24 @@ abstract class Options implements TranslatorAwareInterface return intval($this->resultLimit); } + /** + * Load all API-related settings from the relevant ini file(s). + * + * @return array + */ + public function getAPISettings() + { + // Inherit defaults from searches.ini (if that is not already the + // configured search settings file): + $defaultConfig = $this->configLoader->get('searches')->API; + $defaultSettings = $defaultConfig ? $defaultConfig->toArray() : []; + $localIni = $this->getSearchIni(); + $localConfig = ($localIni !== 'searches') + ? $this->configLoader->get($localIni)->API : null; + $localSettings = $localConfig ? $localConfig->toArray() : []; + return array_merge($defaultSettings, $localSettings); + } + /** * Load all recommendation settings from the relevant ini file. Returns an * associative array where the key is the location of the recommendations (top diff --git a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php index 335d97371be8c44f59dada223331850ea64f42be..2a9e2e4ad7919d77d73f8919c36e89da3e153f13 100644 --- a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php +++ b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php @@ -135,6 +135,20 @@ class SearchApiController extends \VuFind\Controller\AbstractSearch $this->defaultRecordFields[] = $fieldName; } } + + // Load configurations from the search options class: + $settings = $sm->get(\VuFind\Search\Options\PluginManager::class) + ->get($this->searchClassId)->getAPISettings(); + + // Apply all supported configurations: + $configKeys = [ + 'recordAccessPermission', 'searchAccessPermission', 'maxLimit' + ]; + foreach ($configKeys as $key) { + if (isset($settings[$key])) { + $this->$key = $settings[$key]; + } + } } /**