-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheadsearch.xqm
More file actions
186 lines (159 loc) · 6.96 KB
/
eadsearch.xqm
File metadata and controls
186 lines (159 loc) · 6.96 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
module namespace es = 'http://localhost/eadsearch';
import module namespace pf='http://localhost/pubfacets' at "pubfacets.xqm" ;
declare default element namespace "urn:isbn:1-931666-22-9" ; (: EAD2002 :)
(: TODO: add search by [persname, unittitles,] IDs ( top unitid and /titlestmt//num, vi# ),
any text & publisher select & facets, ( other facets if possible? )
:)
(: for order by newest, since there is no timestamps in DB, we need to map db:paths to file system paths
so this link has to match :)
declare variable $es:file_base := '/usr/local/projects/published/' ;
declare variable $es:ORGS := doc( 'ead-inst/ead-inst.xml' );
declare %rest:path( '/search' )
%rest:GET %rest:POST
%rest:query-param( "title", "{$title}" )
%rest:query-param( "subject", "{$subject}")
%rest:query-param( "person", "{$person}")
%rest:query-param( "subj_mode", "{$subj_mode}")
%rest:query-param( "title_mode", "{$title_mode}" )
%rest:query-param( "pers_mode", "{$pers_mode}" )
%rest:query-param( "publisher", "{$publisher}")
%rest:query-param( "text", "{$text}")
%rest:query-param( "start", "{$start}", 1)
%rest:query-param( "count", "{$count}", 25 )
%rest:query-param( "ead3", "{$ead3}", "")
%output:method('html')
%output:version( '5.0')
function es:search( $title as xs:string* , $subject as xs:string*, $person as xs:string*,
$publisher as xs:string?, $text as xs:string*,
$subj_mode as xs:string?, $title_mode as xs:string?, $pers_mode as xs:string?,
$start as xs:int?, $count as xs:int?, $ead3 as xs:string? ) {
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Search</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor"
crossorigin="anonymous" />
</head>
<body style="background-image:url(static/images/web_background.jpg);" >
<div class="container" >
<div class="row m-2" >
<img src="static/images/ARVAS_fullnamelogo.png" class="img-thumbnail" />
</div>
<div class="container m-4" id="search_form">
<form method="get" action="search">
<div>
<dt>Title:</dt>
<dd><input type="text" name="title" label="title" value="{$title ?: '' }" />
{ es:HTMLselect( 'title_mode', ('all', 'any'), $title_mode ) }</dd>
<dt>Subject:</dt>
<dd><input type="text" name="subject" label="subject" value="{$subject ?: ''}"/>
{ es:HTMLselect( 'subj_mode', ('all', 'any'), $subj_mode ) }</dd>
<dt>Persons:</dt>
<dd><input type="text" name="person" label="person" value="{$person ?: ''}" />
{ es:HTMLselect( 'pers_mode', ('all', 'any'), $pers_mode ) }</dd>
<dt>Publisher:</dt>
<dd><input type="text" name="publisher" label="publisher" value="{$publisher ?: ''}" /></dd>
<dt>text (anywhere):</dt>
<dd><input type="text" name="text" label="text" value="{$text ?: ''}" /></dd>
<input type="submit" value="Search" />
<input type="reset" value="Clear Search" onclick="location.href='search'"/>
<input type="hidden" name="count" value="25" />
<input type="hidden" name="start" value="1" />
</div>
</form>
</div><!-- search-form -->
<div class="container" id="search_results">
{ let $docs := es:findBy( collection('published'), 'titlestmt', $title, map{ 'mode' : $title_mode ?: "all" } )
=> es:findBy( 'subject', $subject, map{ 'mode' : $subj_mode ?: "all" } )
=> es:findBy( 'persname', $person, map{ 'mode' : $pers_mode ?: "all" } )
(: => es:findBy( 'publisher', ( $publisher ?: '' ), map{ 'mode' : "phrase"} ) :)
=> es:findByAgencycode( $publisher )
=> es:findBy( 'archdesc', $text, map{ 'mode' : 'all' } )
return
<div><h4> {$start} to { min( ( count($docs), ($start+$count - 1 ) ) ) } of { count($docs) } found:
{ for $p in request:parameter-names()
where ( not(ends-with($p, "_mode")) and not($p = ("start", "count")) and request:parameter($p)[1] )
return concat($p,'=', string-join(request:parameter($p), ';' )) }
</h4>
<ul class="list-group">
{
for $doc in subsequence( es:orderByNewest($docs), $start, $count )
return es:linktodoc( $doc, (if ($ead3) then true() else false()) )
}
</ul>
<div id="publishers" ><h4>Publishers: { count($docs) }</h4><ul class="list-group">
{
let $debug := prof:variables()
for $x in fn:trace( pf:countpubfacets( $docs ) )
where ( array:size($x) = 4 )
return <li class="list-group-item">
<a href="search?{ request:query() }&publisher={ $x(3) }">{ ( $x(3), $x(4)) }</a>
[{$x(1)}]</li> }
</ul>
</div> <!-- publishers -->
</div>
}
</div><!-- search results -->
<div id="next">
<hr/><br/>
<a href="search?{ substring-before(request:query(), '&start=' ) }&start={ string($start + $count) }" >
<input type="button" value="Next Page..." />
</a>
<a href="https://github.com/VAheritage/basexead#readme" target="_blank" style="float:right;">
<input type="button" value="ReadMe: notes & issues" />
</a>
<br/><hr/><br/>
</div> <!-- next -->
</div > <!-- container -->
</body>
</html>
};
declare function es:findBy( $ctx, $field as xs:string, $what as xs:string*, $opt ) {
if( $what[1] ) then
$ctx/*[ft:contains( xquery:eval( ".//*:" || $field, map{ '' : . } ), ($what ! ft:tokenize(.)), $opt )] ! root(.)
else $ctx
};
declare function es:findByAgencycode( $ctx, $code as xs:string? ) {
if ( $code ) then
let $norm := pf:normalize($code)
let $alt := $es:ORGS/inst[@prefix=$norm]/@oclc/text()
let $name := $es:ORGS/inst[@prefix=$norm]/normalize-space()
return $ctx/ead[eadheader/eadid/@mainagencycode/pf:normalize(.) = ( $norm, $alt )]
else $ctx
};
declare function es:linktodoc( $doc, $ead3 as xs:boolean ) {
<li class="list-group-item"><div>
<a href="{ 'view?docId=' || base-uri($doc) || (if ($ead3) then '&ead3=true' else '&ead3=' ) }" >
{ root($doc)/ead/eadheader//titlestmt/titleproper/es:normalize-space(.) }
</a>
<div>{ root($doc)/ead/archdesc/did/unittitle/es:normalize-space(.) }</div>
<div class="publisher">
{ concat(root($doc)//ead/eadheader/eadid/@mainagencycode/string(), ': ', root($doc)/ead/eadheader//publisher/string()) }
</div>
<div class="subjects" >
{ for $s in subsequence($doc//subject/normalize-space(),1,20)
return <i> <a href="search?subject={$s}" >{$s}</a> </i> }
</div>
<br/>
</div></li>
};
declare function es:HTMLselect( $name, $values, $selected as xs:string? ) {
<select name="{$name}">
{ for $v in $values return
if ($v = $selected ) then <option value="{$v}" selected="selected" >{$v}</option>
else
<option value="{$v}" >{$v}</option> }
</select>
};
declare function es:orderByNewest( $c ) {
for $doc in $c
let $path := $es:file_base || db:path( $doc )
let $TS := if (file:exists($path)) then file:last-modified( $path ) else xs:dateTime(xs:date('1970-01-01'))
order by $TS descending
return $doc
};
declare function es:normalize-space( $items as item()* ) {
normalize-space(string-join( $items//descendant-or-self::text(), ' ' ))
};