-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-all-records-to-db.xq
42 lines (38 loc) · 1.51 KB
/
add-all-records-to-db.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";
(: Retrieves metadata records for an entire OAI-PMH collection :)
(: Adds records to BaseX database:)
declare function local:request($base-url as xs:string, $verb as xs:string) as document-node()*
{
let $request := $base-url || $verb
let $response := fn:doc($request)
let $token := $response//oai:resumptionToken/text()
return
if (fn:empty($token)) then
$response
else
($response,
local:resume($base-url, $token))
};
declare function local:resume($base-url as xs:string, $token as xs:string) as document-node()*
{
let $verb := "?verb=ListRecords&resumptionToken="
let $request := $base-url || $verb || $token
let $response := fn:doc($request)
let $new-token := $response//oai:resumptionToken/text()
return
if (fn:empty($new-token)) then
$response
else
($response,
local:resume($base-url, $new-token))
};
let $base-url := "http://dpla.lib.utk.edu/repox/OAIHandler"
let $verb := "?verb=ListRecords&metadataPrefix=MODS"
let $response := local:request($base-url, $verb)
for $record in $response//oai:record
let $id := $record/oai:header/oai:identifier/text()
return(
(: db:replace('cmhf', $record, $id, map { 'addcache': true() }) :)
db:add('all-records', $record, $id, map { 'addcache': true() }),
db:optimize('all-records', true(), map { 'textindex': true(), 'attrindex': true(), 'tokenindex': true(), 'ftindex': true() })
)