Skip to content
Snippets Groups Projects
Commit 122307d6 authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

Make it possible to define format-specific query filters. (#1331)

parent 6de273b2
No related merge requests found
......@@ -1186,6 +1186,10 @@ url = https://www.myendnoteweb.com/EndNoteWeb.html
; SearchApiRecordFields.yaml) are returned when metadata prefix
; "oai_vufind_json" is used.
;
; record_format_filters allows mapping from requested OAI metadataPrefix to query
; filters. They can be used e.g. to limit results to records that can be returned in
; the requested format.
;
;[OAI]
;identifier = myuniversity.edu
;repository_name = "MyUniversity Catalog"
......@@ -1195,6 +1199,7 @@ url = https://www.myendnoteweb.com/EndNoteWeb.html
;set_query['eod_ebooks'] = "format:eBook"
;default_query = "institution:kfu"
;vufind_api_format_fields = "id,authors,cleanIsbn,cleanIssn,formats,title"
;record_format_filters[marc21] = "record_format:marc"
; Proxy Server is Optional.
[Proxy]
......
......@@ -5,7 +5,7 @@
* PHP version 7
*
* Copyright (C) Villanova University 2010.
* Copyright (C) The National Library of Finland 2018.
* Copyright (C) The National Library of Finland 2018-2019.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
......@@ -196,6 +196,13 @@ class Server
*/
protected $vufindApiFields = [];
/**
* Filter queries specific to the requested record format
*
* @var array
*/
protected $recordFormatFilters = [];
/**
* Constructor
*
......@@ -643,6 +650,12 @@ class Server
',', $config->OAI->vufind_api_format_fields ?? ''
)
);
// Initialize filters specific to requested metadataPrefix:
if (isset($config->OAI->record_format_filters)) {
$this->recordFormatFilters
= $config->OAI->record_format_filters->toArray();
}
}
/**
......@@ -741,6 +754,7 @@ class Server
// Figure out how many non-deleted records we need to display:
$recordLimit = ($params['cursor'] + $this->pageSize) - $currentCursor;
$cursorMark = $params['cursorMark'] ?? '';
$format = $params['metadataPrefix'];
// Get non-deleted records from the Solr index:
$set = $params['set'] ?? '';
......@@ -749,10 +763,10 @@ class Server
$until,
$cursorMark,
$recordLimit,
$format,
$set
);
$nonDeletedCount = $result->getResultTotal();
$format = $params['metadataPrefix'];
foreach ($result->getResults() as $doc) {
$this->attachNonDeleted($xml, $doc, $format, $headersOnly, $set);
$currentCursor++;
......@@ -884,12 +898,13 @@ class Server
* @param int $until End date.
* @param string $cursorMark cursorMark for the position in the full result list.
* @param int $limit Max number of full records to return.
* @param string $format Requested record format
* @param string $set Set to limit to (empty string for none).
*
* @return \VuFind\Search\Base\Results Search result object.
*/
protected function listRecordsGetNonDeleted($from, $until, $cursorMark, $limit,
$set = ''
$format, $set = ''
) {
// Set up search parameters:
$results = $this->resultsManager->get($this->searchClassId);
......@@ -922,6 +937,10 @@ class Server
$params->addFilter('(' . $this->defaultQuery . ')');
}
if (!empty($this->recordFormatFilters[$format])) {
$params->addFilter($this->recordFormatFilters[$format]);
}
// Perform a Solr search:
$results->overrideStartRecord(1);
$results->setCursorMark($cursorMark);
......
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