Skip to content
Snippets Groups Projects
Commit e1b18fea authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add configuration for API settings. (#1838)

parent ba035c0a
No related merge requests found
...@@ -188,6 +188,11 @@ view=full ...@@ -188,6 +188,11 @@ view=full
;content[] = IlsStatusMonitor ;content[] = IlsStatusMonitor
content[] = FacetList:Search2 content[] = FacetList:Search2
[API]
;recordAccessPermission = access.api.Record
;searchAccessPermission = access.api.Search
;maxLimit = 100
; ---------- facets.ini settings ---------- ; ---------- facets.ini settings ----------
[Results] [Results]
......
...@@ -733,3 +733,12 @@ view=full ...@@ -733,3 +733,12 @@ view=full
; and that version would be loaded when the user's language was set to German. ; and that version would be loaded when the user's language was set to German.
content[] = IlsStatusMonitor content[] = IlsStatusMonitor
content[] = FacetList 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
...@@ -46,3 +46,10 @@ facet_limit = 30 ...@@ -46,3 +46,10 @@ facet_limit = 30
;[Index] ;[Index]
;url = http://localhost:8983/solr ;url = http://localhost:8983/solr
;default_core = website ;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
...@@ -885,6 +885,24 @@ abstract class Options implements TranslatorAwareInterface ...@@ -885,6 +885,24 @@ abstract class Options implements TranslatorAwareInterface
return intval($this->resultLimit); 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 * Load all recommendation settings from the relevant ini file. Returns an
* associative array where the key is the location of the recommendations (top * associative array where the key is the location of the recommendations (top
......
...@@ -135,6 +135,20 @@ class SearchApiController extends \VuFind\Controller\AbstractSearch ...@@ -135,6 +135,20 @@ class SearchApiController extends \VuFind\Controller\AbstractSearch
$this->defaultRecordFields[] = $fieldName; $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];
}
}
} }
/** /**
......
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