1 | <accessor debug="false" trace="false"> |
---|
2 | <name>/rest/search</name> |
---|
3 | <descr>Search the users workspace.</descr> |
---|
4 | <param mandatory="true"> |
---|
5 | <name>method</name> |
---|
6 | <descr>what do we want to do?</descr> |
---|
7 | <type canonical="true">string</type> |
---|
8 | </param> |
---|
9 | <!-- search --> |
---|
10 | <param> |
---|
11 | <name>keywords</name> |
---|
12 | <descr>search for these keywords</descr> |
---|
13 | <type canonical="true">string-join</type> |
---|
14 | <source> |
---|
15 | <param/> |
---|
16 | <nvp/> |
---|
17 | <default> |
---|
18 | <string/> |
---|
19 | </default> |
---|
20 | </source> |
---|
21 | </param> |
---|
22 | <param> |
---|
23 | <name>fields</name> |
---|
24 | <descr>search in these fields</descr> |
---|
25 | <type canonical="true">string-join</type> |
---|
26 | <source> |
---|
27 | <param/> |
---|
28 | <nvp/> |
---|
29 | <default> |
---|
30 | <string/> |
---|
31 | </default> |
---|
32 | </source> |
---|
33 | </param> |
---|
34 | <param> |
---|
35 | <name>profiles</name> |
---|
36 | <descr>search in these profiles</descr> |
---|
37 | <type canonical="true" join="|">string-join</type> |
---|
38 | <source> |
---|
39 | <nvp name="profile"/> |
---|
40 | <default> |
---|
41 | <string/> |
---|
42 | </default> |
---|
43 | </source> |
---|
44 | </param> |
---|
45 | <param> |
---|
46 | <name>scope</name> |
---|
47 | <descr>the scope (public or private or both) of the DCs</descr> |
---|
48 | <type canonical="true">string</type> |
---|
49 | <source> |
---|
50 | <param/> |
---|
51 | <nvp/> |
---|
52 | <default> |
---|
53 | <string>public</string> |
---|
54 | </default> |
---|
55 | </source> |
---|
56 | </param> |
---|
57 | <param> |
---|
58 | <name>language</name> |
---|
59 | <descr>the language of the keywords</descr> |
---|
60 | <type canonical="true">string</type> |
---|
61 | <source> |
---|
62 | <param/> |
---|
63 | <nvp/> |
---|
64 | <default> |
---|
65 | <string>en</string> |
---|
66 | </default> |
---|
67 | </source> |
---|
68 | </param> |
---|
69 | <param> |
---|
70 | <name>match</name> |
---|
71 | <descr>how to match the keywords (exact or like)</descr> |
---|
72 | <type canonical="true">string</type> |
---|
73 | <source> |
---|
74 | <param/> |
---|
75 | <nvp/> |
---|
76 | <default> |
---|
77 | <string>like</string> |
---|
78 | </default> |
---|
79 | </source> |
---|
80 | </param> |
---|
81 | <param> |
---|
82 | <name>limit</name> |
---|
83 | <descr>limit the number of matches returned</descr> |
---|
84 | <type canonical="true">string</type> |
---|
85 | <source> |
---|
86 | <param/> |
---|
87 | <nvp/> |
---|
88 | <default> |
---|
89 | <string>100</string> |
---|
90 | </default> |
---|
91 | </source> |
---|
92 | </param> |
---|
93 | <param> |
---|
94 | <name>types</name> |
---|
95 | <descr>return only data categories of these types</descr> |
---|
96 | <type canonical="true" join="|">string-join</type> |
---|
97 | <source> |
---|
98 | <nvp name="type"/> |
---|
99 | <default> |
---|
100 | <string/> |
---|
101 | </default> |
---|
102 | </source> |
---|
103 | </param> |
---|
104 | <param> |
---|
105 | <name>view</name> |
---|
106 | <descr>return only data categories in this view</descr> |
---|
107 | <type canonical="true">string</type> |
---|
108 | <source> |
---|
109 | <nvp/> |
---|
110 | <default> |
---|
111 | <string>isocat</string> |
---|
112 | </default> |
---|
113 | </source> |
---|
114 | </param> |
---|
115 | <!-- authorization --> |
---|
116 | <param> |
---|
117 | <name>user</name> |
---|
118 | <descr>the user name</descr> |
---|
119 | <type canonical="true">string</type> |
---|
120 | <source> |
---|
121 | <param/> |
---|
122 | <default> |
---|
123 | <string/> |
---|
124 | </default> |
---|
125 | </source> |
---|
126 | </param> |
---|
127 | <param> |
---|
128 | <name>credentials</name> |
---|
129 | <descr>the user credentials</descr> |
---|
130 | <type canonical="true">string</type> |
---|
131 | <source> |
---|
132 | <param/> |
---|
133 | <default> |
---|
134 | <string/> |
---|
135 | </default> |
---|
136 | </source> |
---|
137 | </param> |
---|
138 | <!-- representation --> |
---|
139 | <param> |
---|
140 | <name>representation</name> |
---|
141 | <descr>the requested representation</descr> |
---|
142 | <type canonical="true">string</type> |
---|
143 | <source> |
---|
144 | <param/> |
---|
145 | <default> |
---|
146 | <string/> |
---|
147 | </default> |
---|
148 | </source> |
---|
149 | </param> |
---|
150 | <param> |
---|
151 | <name>Accept</name> |
---|
152 | <descr>the accepted representation</descr> |
---|
153 | <type canonical="true">string</type> |
---|
154 | <source> |
---|
155 | <param/> |
---|
156 | <default> |
---|
157 | <string/> |
---|
158 | </default> |
---|
159 | </source> |
---|
160 | </param> |
---|
161 | <params/> |
---|
162 | <idoc> |
---|
163 | <!-- determine the requested representation --> |
---|
164 | <instr> |
---|
165 | <type>ISOcat.interface.rest.dcs.determine.representation</type> |
---|
166 | <representation>var:representation</representation> |
---|
167 | <accept>var:Accept</accept> |
---|
168 | <target>var:representation</target> |
---|
169 | </instr> |
---|
170 | <accessor-debug> |
---|
171 | <instr> |
---|
172 | <type>log</type> |
---|
173 | <operand>var:params</operand> |
---|
174 | </instr> |
---|
175 | </accessor-debug> |
---|
176 | <!-- if no keywords then return an error --> |
---|
177 | <if> |
---|
178 | <cond> |
---|
179 | <instr> |
---|
180 | <type>sloot.xpath2eval</type> |
---|
181 | <operand>var:keywords</operand> |
---|
182 | <operator> |
---|
183 | <xpath>normalize-space(.)=''</xpath> |
---|
184 | </operator> |
---|
185 | <target>this:cond</target> |
---|
186 | </instr> |
---|
187 | </cond> |
---|
188 | <then> |
---|
189 | <instr> |
---|
190 | <type>throw</type> |
---|
191 | <operand> |
---|
192 | <ex> |
---|
193 | <id>ISOcat[BAD REQUEST]</id> |
---|
194 | <message>There are no keywords supplied to search for!</message> |
---|
195 | </ex> |
---|
196 | </operand> |
---|
197 | </instr> |
---|
198 | </then> |
---|
199 | </if> |
---|
200 | <!-- do we need to challenge for credentials --> |
---|
201 | <if> |
---|
202 | <cond> |
---|
203 | <instr> |
---|
204 | <type>sloot.xquery</type> |
---|
205 | <operator> |
---|
206 | <b>{ |
---|
207 | if ( |
---|
208 | (normalize-space($scope)!='public') |
---|
209 | and (normalize-space($user)!='guest') |
---|
210 | and (normalize-space($credentials)='') |
---|
211 | ) |
---|
212 | then ('t') |
---|
213 | else ('f') |
---|
214 | }</b> |
---|
215 | </operator> |
---|
216 | <scope>var:scope</scope> |
---|
217 | <user>var:user</user> |
---|
218 | <credentials>var:credentials</credentials> |
---|
219 | <target>this:cond</target> |
---|
220 | </instr> |
---|
221 | </cond> |
---|
222 | <then> |
---|
223 | <instr> |
---|
224 | <type>throw</type> |
---|
225 | <operand> |
---|
226 | <ex> |
---|
227 | <id>ISOcat[UNAUTHORIZED ACCESS]</id> |
---|
228 | <message>Sorry, you need to authenticate to access this resource.</message> |
---|
229 | </ex> |
---|
230 | </operand> |
---|
231 | </instr> |
---|
232 | </then> |
---|
233 | </if> |
---|
234 | <!-- check the credentials --> |
---|
235 | <if> |
---|
236 | <cond> |
---|
237 | <instr> |
---|
238 | <type>sloot.xpath2eval</type> |
---|
239 | <operand>var:credentials</operand> |
---|
240 | <operator> |
---|
241 | <xpath>normalize-space(.)=''</xpath> |
---|
242 | </operator> |
---|
243 | <target>this:cond</target> |
---|
244 | </instr> |
---|
245 | </cond> |
---|
246 | <then> |
---|
247 | <instr> |
---|
248 | <type>copy</type> |
---|
249 | <operand> |
---|
250 | <string>guest:guest</string> |
---|
251 | </operand> |
---|
252 | <target>var:credentials</target> |
---|
253 | </instr> |
---|
254 | </then> |
---|
255 | </if> |
---|
256 | <!-- determine the user workspace --> |
---|
257 | <if> |
---|
258 | <cond> |
---|
259 | <instr> |
---|
260 | <type>sloot.xpath2eval</type> |
---|
261 | <operand>var:user</operand> |
---|
262 | <operator> |
---|
263 | <xpath>normalize-space(.)=''</xpath> |
---|
264 | </operator> |
---|
265 | <target>this:cond</target> |
---|
266 | </instr> |
---|
267 | </cond> |
---|
268 | <then> |
---|
269 | <instr> |
---|
270 | <type>sloot.xpath2eval</type> |
---|
271 | <operand>var:credentials</operand> |
---|
272 | <operator> |
---|
273 | <xpath>substring-before(.,':')</xpath> |
---|
274 | </operator> |
---|
275 | <param> |
---|
276 | <return> |
---|
277 | <canonical/> |
---|
278 | <string/> |
---|
279 | </return> |
---|
280 | </param> |
---|
281 | <target>var:user</target> |
---|
282 | </instr> |
---|
283 | </then> |
---|
284 | </if> |
---|
285 | <accessor-debug> |
---|
286 | <instr> |
---|
287 | <type>log</type> |
---|
288 | <operand>var:user</operand> |
---|
289 | </instr> |
---|
290 | <instr> |
---|
291 | <type>log</type> |
---|
292 | <operand>var:credentials</operand> |
---|
293 | </instr> |
---|
294 | </accessor-debug> |
---|
295 | <!-- cleanup the view name --> |
---|
296 | <instr> |
---|
297 | <type>sloot.xpath2eval</type> |
---|
298 | <operand>var:view</operand> |
---|
299 | <operator> |
---|
300 | <xpath>translate(.,'+',' ')</xpath> |
---|
301 | </operator> |
---|
302 | <param> |
---|
303 | <return> |
---|
304 | <canonical/> |
---|
305 | <string/> |
---|
306 | </return> |
---|
307 | </param> |
---|
308 | <target>var:view</target> |
---|
309 | </instr> |
---|
310 | <!-- handle the request --> |
---|
311 | <choose> |
---|
312 | <cond> |
---|
313 | <instr> |
---|
314 | <type>sloot.xpath2eval</type> |
---|
315 | <operand>var:method</operand> |
---|
316 | <operator> |
---|
317 | <xpath>.='GET'</xpath> |
---|
318 | </operator> |
---|
319 | <target>this:cond</target> |
---|
320 | </instr> |
---|
321 | </cond> |
---|
322 | <then> |
---|
323 | <if> |
---|
324 | <cond> |
---|
325 | <instr> |
---|
326 | <type>sloot.xpath2eval</type> |
---|
327 | <operand>var:language</operand> |
---|
328 | <operator> |
---|
329 | <xpath>.!='und'</xpath> |
---|
330 | </operator> |
---|
331 | <target>this:cond</target> |
---|
332 | </instr> |
---|
333 | </cond> |
---|
334 | <then> |
---|
335 | <!-- try to find out if the language specific stemming and stopping should be switched off --> |
---|
336 | <instr> |
---|
337 | <type>xslt2</type> |
---|
338 | <operand>active:sloot.void</operand> |
---|
339 | <operator> |
---|
340 | <xsl:stylesheet |
---|
341 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" |
---|
342 | xmlns:functx="http://www.functx.com" |
---|
343 | xmlns:xs="http://www.w3.org/2001/XMLSchema" |
---|
344 | xmlns:isocat="http://www.isocat.org/"> |
---|
345 | <xsl:include href="active:sloot.functx.xsl"/> |
---|
346 | |
---|
347 | <xsl:param name="debug" select="'f'"/> |
---|
348 | |
---|
349 | <!-- params --> |
---|
350 | <xsl:param name="keywords" select="()"/> |
---|
351 | <xsl:param name="language" select="()"/> |
---|
352 | |
---|
353 | <!-- globals --> |
---|
354 | <xsl:variable name="all-language" select="document('active:ISOcat.manage.dm.languages')"/> |
---|
355 | |
---|
356 | <xsl:variable name="def-language" select="'und'"/> |
---|
357 | |
---|
358 | <!-- interpret params --> |
---|
359 | <xsl:variable name="use-keywords" select="$keywords/tokenize(replace(.,':',' '),'\s+')[normalize-space(.)!='']"/> |
---|
360 | <xsl:variable name="use-query" select="string-join($use-keywords,' | ')"/><!-- by default make an OR query --> |
---|
361 | <xsl:variable name="use-language" as="xs:string*"> |
---|
362 | <xsl:choose> |
---|
363 | <xsl:when test="exists($language) and exists(functx:value-intersect($all-language//language[@search!='simple']/@tag,$language))"> |
---|
364 | <xsl:sequence select="$language"/> |
---|
365 | </xsl:when> |
---|
366 | <xsl:otherwise> |
---|
367 | <xsl:sequence select="$def-language"/> |
---|
368 | </xsl:otherwise> |
---|
369 | </xsl:choose> |
---|
370 | </xsl:variable> |
---|
371 | <xsl:variable name="use-language-id" as="xs:string*"> |
---|
372 | <xsl:choose> |
---|
373 | <xsl:when test="exists($all-language//language[@tag=$use-language])"> |
---|
374 | <xsl:sequence select="$all-language//language[@tag=$use-language]/@isocat:id"/> |
---|
375 | </xsl:when> |
---|
376 | <xsl:otherwise> |
---|
377 | <xsl:sequence select="'0'"/> |
---|
378 | </xsl:otherwise> |
---|
379 | </xsl:choose> |
---|
380 | </xsl:variable> |
---|
381 | <xsl:variable name="use-config" as="xs:string*"> |
---|
382 | <xsl:choose> |
---|
383 | <xsl:when test="exists($all-language//language[@tag=$use-language])"> |
---|
384 | <xsl:sequence select="$all-language//language[@tag=$use-language]/@search"/> |
---|
385 | </xsl:when> |
---|
386 | <xsl:otherwise> |
---|
387 | <xsl:sequence select="'simple'"/> |
---|
388 | </xsl:otherwise> |
---|
389 | </xsl:choose> |
---|
390 | </xsl:variable> |
---|
391 | |
---|
392 | <xsl:template match="/"> |
---|
393 | <xsl:if test="$debug='t'"> |
---|
394 | <xsl:message>DBG:use-keywords[<xsl:value-of select="count($use-keywords)"/>][<xsl:value-of select="string-join($use-keywords,', ')"/>]</xsl:message> |
---|
395 | <xsl:message>DBG:use-query[<xsl:value-of select="$use-query"/>]</xsl:message> |
---|
396 | <xsl:message>DBG:use-language[<xsl:value-of select="$use-language"/>]</xsl:message> |
---|
397 | <xsl:message>DBG:use-language-id[<xsl:value-of select="$use-language-id"/>]</xsl:message> |
---|
398 | <xsl:message>DBG:use-config[<xsl:value-of select="$use-config"/>]</xsl:message> |
---|
399 | </xsl:if> |
---|
400 | <sql> |
---|
401 | SELECT |
---|
402 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query |
---|
403 | ; |
---|
404 | </sql> |
---|
405 | </xsl:template> |
---|
406 | </xsl:stylesheet> |
---|
407 | </operator> |
---|
408 | <debug>var:accessor-debug</debug> |
---|
409 | <keywords>var:keywords</keywords> |
---|
410 | <language>var:language</language> |
---|
411 | <target>var:sql</target> |
---|
412 | </instr> |
---|
413 | <accessor-debug> |
---|
414 | <instr> |
---|
415 | <type>copy</type> |
---|
416 | <operand>var:sql</operand> |
---|
417 | <target>ffcpl:/trace/search.test.sql.xml</target> |
---|
418 | </instr> |
---|
419 | </accessor-debug> |
---|
420 | <instr> |
---|
421 | <type>ISOcat.manage.system.query</type> |
---|
422 | <query>var:sql</query> |
---|
423 | <target>var:result</target> |
---|
424 | </instr> |
---|
425 | <accessor-debug> |
---|
426 | <instr> |
---|
427 | <type>copy</type> |
---|
428 | <operand>var:result</operand> |
---|
429 | <target>ffcpl:/trace/search.test.result.xml</target> |
---|
430 | </instr> |
---|
431 | </accessor-debug> |
---|
432 | <if> |
---|
433 | <cond> |
---|
434 | <instr> |
---|
435 | <type>sloot.xpath2eval</type> |
---|
436 | <operand>var:result</operand> |
---|
437 | <operator> |
---|
438 | <xpath>normalize-space(.)=''</xpath> |
---|
439 | </operator> |
---|
440 | <target>this:cond</target> |
---|
441 | </instr> |
---|
442 | </cond> |
---|
443 | <then> |
---|
444 | <instr> |
---|
445 | <type>copy</type> |
---|
446 | <operand> |
---|
447 | <string>und</string> |
---|
448 | </operand> |
---|
449 | <target>var:language</target> |
---|
450 | </instr> |
---|
451 | <instr> |
---|
452 | <type>sloot.log</type> |
---|
453 | <operand> |
---|
454 | <msg>WRN: switch off language specific stemming and stopping as the query string would become empty</msg> |
---|
455 | </operand> |
---|
456 | </instr> |
---|
457 | </then> |
---|
458 | <else> |
---|
459 | <!-- noop: NK needs an else branch otherwise it throws an exception --> |
---|
460 | <instr> |
---|
461 | <type>copy</type> |
---|
462 | <operand>var:language</operand> |
---|
463 | <target>var:language</target> |
---|
464 | </instr> |
---|
465 | </else> |
---|
466 | </if> |
---|
467 | </then> |
---|
468 | </if> |
---|
469 | <!-- the actual search --> |
---|
470 | <instr> |
---|
471 | <type>xslt2</type> |
---|
472 | <operand>active:sloot.void</operand> |
---|
473 | <operator> |
---|
474 | <xsl:stylesheet |
---|
475 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" |
---|
476 | xmlns:functx="http://www.functx.com" |
---|
477 | xmlns:xs="http://www.w3.org/2001/XMLSchema" |
---|
478 | xmlns:isocat="http://www.isocat.org/"> |
---|
479 | <xsl:include href="active:sloot.functx.xsl"/> |
---|
480 | |
---|
481 | <xsl:param name="debug" select="'f'"/> |
---|
482 | |
---|
483 | <!-- params --> |
---|
484 | <xsl:param name="keywords" select="()"/> |
---|
485 | <xsl:param name="fields" select="()"/> |
---|
486 | <xsl:param name="scope" select="()"/> |
---|
487 | <xsl:param name="match" select="()"/> |
---|
488 | <xsl:param name="language" select="()"/> |
---|
489 | <xsl:param name="profiles" select="''"/> |
---|
490 | <xsl:param name="types" select="''"/> |
---|
491 | |
---|
492 | <!-- globals --> |
---|
493 | <xsl:variable name="all-fields" select="('key','identifier','name','element','definition','explanation','example','note')"/> |
---|
494 | <xsl:variable name="all-scope" select="('public','private','both')"/> |
---|
495 | <xsl:variable name="all-match" select="('exact','like')"/> |
---|
496 | <xsl:variable name="all-complex-types" select="('open','constrained','closed')"/> |
---|
497 | <xsl:variable name="all-types" select="('container','simple','complex',$all-complex-types)"/> |
---|
498 | <xsl:variable name="all-language" select="document('active:ISOcat.manage.dm.languages')"/> |
---|
499 | |
---|
500 | <xsl:variable name="def-fields" select="$all-fields"/> |
---|
501 | <xsl:variable name="def-scope" select="'public'"/> |
---|
502 | <xsl:variable name="def-match" select="'like'"/> |
---|
503 | <xsl:variable name="def-language" select="'und'"/> |
---|
504 | <xsl:variable name="def-types" select="$all-types"/> |
---|
505 | |
---|
506 | <xsl:variable name="def-normalize" select="'8|32'"/> <!-- see http://www.postgresql.org/docs/8.4/interactive/textsearch-controls.html#TEXTSEARCH-RANKING --> |
---|
507 | <xsl:variable name="def-aggregate" select="'AVG'"/> |
---|
508 | <xsl:variable name="def-precision" select="'2'"/> |
---|
509 | <xsl:variable name="def-identifier-weight" select="3.0"/> |
---|
510 | <xsl:variable name="def-name-weight" select="2.0"/> |
---|
511 | <xsl:variable name="def-text-weight" select="1.0"/> |
---|
512 | |
---|
513 | <!-- interpret params --> |
---|
514 | <xsl:variable name="param-fields" select="$fields/tokenize(.,'\s+')[normalize-space(.)!='']"/> |
---|
515 | <xsl:variable name="use-fields" as="xs:string*"> |
---|
516 | <xsl:choose> |
---|
517 | <xsl:when test="exists(functx:value-intersect($all-fields,$param-fields))"> |
---|
518 | <xsl:sequence select="functx:value-intersect($all-fields,$param-fields)"/> |
---|
519 | </xsl:when> |
---|
520 | <xsl:otherwise> |
---|
521 | <xsl:sequence select="($def-fields)"/> |
---|
522 | </xsl:otherwise> |
---|
523 | </xsl:choose> |
---|
524 | </xsl:variable> |
---|
525 | <xsl:variable name="use-keywords" select="$keywords/tokenize(replace(.,':',' '),'\s+')[normalize-space(.)!='']"/> |
---|
526 | <xsl:variable name="use-query" select="string-join($use-keywords,' | ')"/><!-- by default make an OR query --> |
---|
527 | <xsl:variable name="use-phrase" select="string-join($use-keywords,' ')"/> |
---|
528 | <xsl:variable name="use-scope" as="xs:string*"> |
---|
529 | <xsl:choose> |
---|
530 | <xsl:when test="exists($scope) and exists(functx:value-intersect($all-scope,$scope))"> |
---|
531 | <xsl:sequence select="$scope"/> |
---|
532 | </xsl:when> |
---|
533 | <xsl:otherwise> |
---|
534 | <xsl:sequence select="$def-scope"/> |
---|
535 | </xsl:otherwise> |
---|
536 | </xsl:choose> |
---|
537 | </xsl:variable> |
---|
538 | <xsl:variable name="use-match" as="xs:string*"> |
---|
539 | <xsl:choose> |
---|
540 | <xsl:when test="exists($match) and exists(functx:value-intersect($all-match,$match))"> |
---|
541 | <xsl:sequence select="$match"/> |
---|
542 | </xsl:when> |
---|
543 | <xsl:otherwise> |
---|
544 | <xsl:sequence select="$def-match"/> |
---|
545 | </xsl:otherwise> |
---|
546 | </xsl:choose> |
---|
547 | </xsl:variable> |
---|
548 | <xsl:variable name="use-language" as="xs:string*"> |
---|
549 | <xsl:choose> |
---|
550 | <xsl:when test="exists($language) and exists(functx:value-intersect($all-language//language[@search!='simple']/@tag,$language))"> |
---|
551 | <xsl:sequence select="$language"/> |
---|
552 | </xsl:when> |
---|
553 | <xsl:otherwise> |
---|
554 | <xsl:sequence select="$def-language"/> |
---|
555 | </xsl:otherwise> |
---|
556 | </xsl:choose> |
---|
557 | </xsl:variable> |
---|
558 | <xsl:variable name="use-language-id" as="xs:string*"> |
---|
559 | <xsl:choose> |
---|
560 | <xsl:when test="exists($all-language//language[@tag=$use-language])"> |
---|
561 | <xsl:sequence select="$all-language//language[@tag=$use-language]/@isocat:id"/> |
---|
562 | </xsl:when> |
---|
563 | <xsl:otherwise> |
---|
564 | <xsl:sequence select="'0'"/> |
---|
565 | </xsl:otherwise> |
---|
566 | </xsl:choose> |
---|
567 | </xsl:variable> |
---|
568 | <xsl:variable name="use-config" as="xs:string*"> |
---|
569 | <xsl:choose> |
---|
570 | <xsl:when test="exists($all-language//language[@tag=$use-language])"> |
---|
571 | <xsl:sequence select="$all-language//language[@tag=$use-language]/@search"/> |
---|
572 | </xsl:when> |
---|
573 | <xsl:otherwise> |
---|
574 | <xsl:sequence select="'simple'"/> |
---|
575 | </xsl:otherwise> |
---|
576 | </xsl:choose> |
---|
577 | </xsl:variable> |
---|
578 | <xsl:variable name="use-profiles" select="$profiles/tokenize(.,'\|')[normalize-space(.)!='']"/> |
---|
579 | <xsl:variable name="param-types" select="$types/tokenize(.,'\|')[normalize-space(.)!='']"/> |
---|
580 | <xsl:variable name="use-types" as="xs:string*"> |
---|
581 | <xsl:choose> |
---|
582 | <xsl:when test="exists(functx:value-intersect($all-types,$param-types))"> |
---|
583 | <xsl:sequence select="functx:value-intersect($all-types,($param-types,if (exists(index-of($param-types,'complex'))) then ($all-complex-types) else ())[.!='complex'])"/> |
---|
584 | </xsl:when> |
---|
585 | <xsl:otherwise> |
---|
586 | <xsl:sequence select="($def-types)"/> |
---|
587 | </xsl:otherwise> |
---|
588 | </xsl:choose> |
---|
589 | </xsl:variable> |
---|
590 | |
---|
591 | <xsl:variable name="use-normalize" select="$def-normalize"/> |
---|
592 | <xsl:variable name="use-aggregate" select="$def-aggregate"/> |
---|
593 | <xsl:variable name="use-precision" select="$def-precision"/> |
---|
594 | <xsl:variable name="use-identifier-weight" select="$def-identifier-weight"/> |
---|
595 | <xsl:variable name="use-name-weight" select="$def-name-weight"/> |
---|
596 | <xsl:variable name="use-text-weight" select="$def-text-weight"/> |
---|
597 | |
---|
598 | <xsl:template match="/"> |
---|
599 | <xsl:if test="$debug='t'"> |
---|
600 | <xsl:message>DBG:fields[<xsl:value-of select="count($fields)"/>][<xsl:value-of select="string-join($fields,', ')"/>]</xsl:message> |
---|
601 | <xsl:message>DBG:param-fields[<xsl:value-of select="count($param-fields)"/>][<xsl:value-of select="string-join($param-fields,', ')"/>]</xsl:message> |
---|
602 | |
---|
603 | <xsl:message>DBG:use-fields[<xsl:value-of select="count($use-fields)"/>][<xsl:value-of select="string-join($use-fields,', ')"/>]</xsl:message> |
---|
604 | <xsl:message>DBG:use-keywords[<xsl:value-of select="count($use-keywords)"/>][<xsl:value-of select="string-join($use-keywords,', ')"/>]</xsl:message> |
---|
605 | <xsl:message>DBG:use-query[<xsl:value-of select="$use-query"/>]</xsl:message> |
---|
606 | <xsl:message>DBG:use-phrase[<xsl:value-of select="$use-phrase"/>]</xsl:message> |
---|
607 | <xsl:message>DBG:use-scope[<xsl:value-of select="$use-scope"/>]</xsl:message> |
---|
608 | <xsl:message>DBG:use-profiles[<xsl:value-of select="count($use-profiles)"/>][<xsl:value-of select="string-join($use-profiles,', ')"/>]</xsl:message> |
---|
609 | <xsl:message>DBG:use-types[<xsl:value-of select="count($use-types)"/>][<xsl:value-of select="string-join($use-types,', ')"/>]</xsl:message> |
---|
610 | <xsl:message>DBG:use-match[<xsl:value-of select="$use-match"/>]</xsl:message> |
---|
611 | <xsl:message>DBG:use-language[<xsl:value-of select="$use-language"/>]</xsl:message> |
---|
612 | <xsl:message>DBG:use-language-id[<xsl:value-of select="$use-language-id"/>]</xsl:message> |
---|
613 | <xsl:message>DBG:use-config[<xsl:value-of select="$use-config"/>]</xsl:message> |
---|
614 | <xsl:message>DBG:use-normalize[<xsl:value-of select="$use-normalize"/>]</xsl:message> |
---|
615 | <xsl:message>DBG:use-aggregate[<xsl:value-of select="$use-aggregate"/>]</xsl:message> |
---|
616 | <xsl:message>DBG:use-precision[<xsl:value-of select="$use-precision"/>]</xsl:message> |
---|
617 | <xsl:message>DBG:use-identifier-weight[<xsl:value-of select="$use-identifier-weight"/>]</xsl:message> |
---|
618 | <xsl:message>DBG:use-name-weight[<xsl:value-of select="$use-name-weight"/>]</xsl:message> |
---|
619 | <xsl:message>DBG:use-text-weight[<xsl:value-of select="$use-text-weight"/>]</xsl:message> |
---|
620 | </xsl:if> |
---|
621 | <xsl:choose> |
---|
622 | <xsl:when test="exists($use-keywords)"> |
---|
623 | <sql> |
---|
624 | SELECT |
---|
625 | core_data_category.id AS id, |
---|
626 | core_data_category.private AS private, |
---|
627 | rank |
---|
628 | FROM |
---|
629 | core_data_category |
---|
630 | JOIN |
---|
631 | ( |
---|
632 | SELECT |
---|
633 | dc AS dc, |
---|
634 | ROUND(<xsl:value-of select="$use-aggregate"/>(rank)::numeric,<xsl:value-of select="$use-precision"/>) AS rank |
---|
635 | FROM |
---|
636 | ( |
---|
637 | <xsl:for-each select="$use-fields"> |
---|
638 | <xsl:if test="$debug='t'"> |
---|
639 | <xsl:message>DBG: field[<xsl:value-of select="."/>]</xsl:message> |
---|
640 | </xsl:if> |
---|
641 | <xsl:choose> |
---|
642 | <xsl:when test=".='key'"> |
---|
643 | SELECT DISTINCT |
---|
644 | id AS dc, |
---|
645 | 10 AS rank |
---|
646 | FROM |
---|
647 | core_data_category |
---|
648 | WHERE |
---|
649 | id IN ( |
---|
650 | <xsl:for-each select="$use-keywords[replace(.,'[^0-9]','')!='']"> |
---|
651 | <xsl:value-of select="replace(.,'[^0-9]','')"/> |
---|
652 | <xsl:text>,</xsl:text> |
---|
653 | </xsl:for-each> |
---|
654 | 0 |
---|
655 | ) |
---|
656 | </xsl:when> |
---|
657 | <xsl:when test=".='identifier' and $use-match='exact'"> |
---|
658 | SELECT DISTINCT |
---|
659 | id AS dc, |
---|
660 | 1 * <xsl:value-of select="$use-identifier-weight"/> AS rank |
---|
661 | FROM |
---|
662 | core_data_category |
---|
663 | WHERE |
---|
664 | identifier = '<xsl:value-of select="replace($use-phrase,'''','\\''')"/>' |
---|
665 | </xsl:when> |
---|
666 | <xsl:when test=".='identifier' and $use-match='like' and $use-language='en'"> |
---|
667 | SELECT DISTINCT |
---|
668 | id AS dc, |
---|
669 | ts_rank_cd(search_language, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-identifier-weight"/> AS rank |
---|
670 | FROM |
---|
671 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
672 | core_data_category |
---|
673 | WHERE |
---|
674 | search_language @@ query |
---|
675 | </xsl:when> |
---|
676 | <xsl:when test=".='identifier' and $use-match='like' and $use-language!='en'"> |
---|
677 | SELECT DISTINCT |
---|
678 | id AS dc, |
---|
679 | ts_rank_cd(search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-identifier-weight"/> AS rank |
---|
680 | FROM |
---|
681 | to_tsquery('simple','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
682 | core_data_category |
---|
683 | WHERE |
---|
684 | search @@ query |
---|
685 | </xsl:when> |
---|
686 | <xsl:when test=".='element' and $use-match='exact'"> |
---|
687 | SELECT DISTINCT |
---|
688 | generic_name.owner AS dc, |
---|
689 | 1 * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
690 | FROM |
---|
691 | generic_name |
---|
692 | WHERE |
---|
693 | owner_type = 'data category' |
---|
694 | AND |
---|
695 | name_type = 'data element name' |
---|
696 | AND |
---|
697 | generic_name.name = '<xsl:value-of select="replace($use-phrase,'''','\\''')"/>' |
---|
698 | </xsl:when> |
---|
699 | <xsl:when test=".='element' and $use-match='like' and $use-language!='en'"> |
---|
700 | SELECT DISTINCT |
---|
701 | generic_name.owner AS dc, |
---|
702 | ts_rank_cd(generic_name.search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
703 | FROM |
---|
704 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
705 | generic_name |
---|
706 | WHERE |
---|
707 | owner_type = 'data category' |
---|
708 | AND |
---|
709 | name_type = 'data element name' |
---|
710 | AND |
---|
711 | generic_name.search @@ query |
---|
712 | </xsl:when> |
---|
713 | <xsl:when test=".='element' and $use-match='like' and $use-language='en'"> |
---|
714 | SELECT DISTINCT |
---|
715 | generic_name.owner AS dc, |
---|
716 | ts_rank_cd(generic_name.search_language, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
717 | FROM |
---|
718 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
719 | generic_name |
---|
720 | WHERE |
---|
721 | owner_type = 'data category' |
---|
722 | AND |
---|
723 | name_type = 'data element name' |
---|
724 | AND |
---|
725 | generic_name.search_language @@ query |
---|
726 | AND |
---|
727 | generic_name.language = <xsl:value-of select="$use-language-id"/> |
---|
728 | </xsl:when> |
---|
729 | <xsl:when test=".='name' and $use-match='exact'"> |
---|
730 | SELECT DISTINCT |
---|
731 | core_language_section.dc AS dc, |
---|
732 | 1 * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
733 | FROM |
---|
734 | generic_name |
---|
735 | JOIN |
---|
736 | core_language_section |
---|
737 | ON |
---|
738 | core_language_section.id = generic_name.owner |
---|
739 | WHERE |
---|
740 | owner_type = 'language section' |
---|
741 | AND |
---|
742 | name_type = 'name section' |
---|
743 | AND |
---|
744 | generic_name.name = '<xsl:value-of select="replace($use-phrase,'''','\\''')"/>' |
---|
745 | </xsl:when> |
---|
746 | <xsl:when test=".='name' and $use-match='like' and $use-language='und'"> |
---|
747 | SELECT DISTINCT |
---|
748 | core_language_section.dc AS dc, |
---|
749 | ts_rank_cd(generic_name.search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
750 | FROM |
---|
751 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
752 | generic_name |
---|
753 | JOIN |
---|
754 | core_language_section |
---|
755 | ON |
---|
756 | core_language_section.id = generic_name.owner |
---|
757 | WHERE |
---|
758 | owner_type = 'language section' |
---|
759 | AND |
---|
760 | name_type = 'name section' |
---|
761 | AND |
---|
762 | generic_name.search @@ query |
---|
763 | </xsl:when> |
---|
764 | <xsl:when test=".='name' and $use-match='like' and $use-language!='und'"> |
---|
765 | SELECT DISTINCT |
---|
766 | core_language_section.dc AS dc, |
---|
767 | ts_rank_cd(generic_name.search_language, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
768 | FROM |
---|
769 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
770 | generic_name |
---|
771 | JOIN |
---|
772 | core_language_section |
---|
773 | ON |
---|
774 | core_language_section.id = generic_name.owner |
---|
775 | WHERE |
---|
776 | owner_type = 'language section' |
---|
777 | AND |
---|
778 | name_type = 'name section' |
---|
779 | AND |
---|
780 | generic_name.search_language @@ query |
---|
781 | AND |
---|
782 | generic_name.language = <xsl:value-of select="$use-language-id"/> |
---|
783 | |
---|
784 | <!-- also match name section for other languages using simple search --> |
---|
785 | UNION |
---|
786 | |
---|
787 | SELECT DISTINCT |
---|
788 | core_language_section.dc AS dc, |
---|
789 | ts_rank_cd(generic_name.search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-name-weight"/> AS rank |
---|
790 | FROM |
---|
791 | to_tsquery('simple','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
792 | generic_name |
---|
793 | JOIN |
---|
794 | core_language_section |
---|
795 | ON |
---|
796 | core_language_section.id = generic_name.owner |
---|
797 | WHERE |
---|
798 | owner_type = 'language section' |
---|
799 | AND |
---|
800 | name_type = 'name section' |
---|
801 | AND |
---|
802 | generic_name.search @@ query |
---|
803 | AND |
---|
804 | generic_name.language != <xsl:value-of select="$use-language-id"/> |
---|
805 | </xsl:when> |
---|
806 | <xsl:when test="$use-match='exact'"> |
---|
807 | SELECT DISTINCT |
---|
808 | core_language_section.dc AS dc, |
---|
809 | 1 * <xsl:value-of select="$use-text-weight"/> AS rank |
---|
810 | FROM |
---|
811 | generic_text |
---|
812 | JOIN |
---|
813 | core_language_section |
---|
814 | ON |
---|
815 | core_language_section.id = generic_text.owner |
---|
816 | WHERE |
---|
817 | owner_type = 'language section' |
---|
818 | AND |
---|
819 | text_type = '<xsl:value-of select="."/>' |
---|
820 | AND |
---|
821 | position('<xsl:value-of select="replace($use-phrase,'''','\\''')"/>' in generic_text.text) > 0 |
---|
822 | </xsl:when> |
---|
823 | <xsl:when test="$use-language='und'"> |
---|
824 | SELECT DISTINCT |
---|
825 | core_language_section.dc AS dc, |
---|
826 | ts_rank_cd(generic_text.search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-text-weight"/> AS rank |
---|
827 | FROM |
---|
828 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
829 | generic_text |
---|
830 | JOIN |
---|
831 | core_language_section |
---|
832 | ON |
---|
833 | core_language_section.id = generic_text.owner |
---|
834 | WHERE |
---|
835 | owner_type = 'language section' |
---|
836 | AND |
---|
837 | text_type = '<xsl:value-of select="."/>' |
---|
838 | AND |
---|
839 | generic_text.search @@ query |
---|
840 | </xsl:when> |
---|
841 | <xsl:when test="$use-language!='und'"> |
---|
842 | SELECT DISTINCT |
---|
843 | core_language_section.dc AS dc, |
---|
844 | ts_rank_cd(generic_text.search_language, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-text-weight"/> AS rank |
---|
845 | FROM |
---|
846 | to_tsquery('<xsl:value-of select="$use-config"/>','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
847 | generic_text |
---|
848 | JOIN |
---|
849 | core_language_section |
---|
850 | ON |
---|
851 | core_language_section.id = generic_text.owner |
---|
852 | WHERE |
---|
853 | owner_type = 'language section' |
---|
854 | AND |
---|
855 | text_type = '<xsl:value-of select="."/>' |
---|
856 | AND |
---|
857 | generic_text.search_language @@ query |
---|
858 | AND |
---|
859 | generic_text.language = <xsl:value-of select="$use-language-id"/> |
---|
860 | |
---|
861 | <!-- also match text for other languages using simple search --> |
---|
862 | UNION |
---|
863 | |
---|
864 | SELECT DISTINCT |
---|
865 | core_language_section.dc AS dc, |
---|
866 | ts_rank_cd(generic_text.search, query, <xsl:value-of select="$use-normalize"/>) * <xsl:value-of select="$use-text-weight"/> AS rank |
---|
867 | FROM |
---|
868 | to_tsquery('simple','<xsl:value-of select="replace($use-query,'''','\\''')"/>') query, |
---|
869 | generic_text |
---|
870 | JOIN |
---|
871 | core_language_section |
---|
872 | ON |
---|
873 | core_language_section.id = generic_text.owner |
---|
874 | WHERE |
---|
875 | owner_type = 'language section' |
---|
876 | AND |
---|
877 | text_type = '<xsl:value-of select="."/>' |
---|
878 | AND |
---|
879 | generic_text.search @@ query |
---|
880 | AND |
---|
881 | generic_text.language != <xsl:value-of select="$use-language-id"/> |
---|
882 | </xsl:when> |
---|
883 | </xsl:choose> |
---|
884 | <xsl:if test="position()!=last()"> |
---|
885 | UNION |
---|
886 | </xsl:if> |
---|
887 | </xsl:for-each> |
---|
888 | ) AS m |
---|
889 | GROUP BY dc |
---|
890 | ) AS dm |
---|
891 | ON |
---|
892 | core_data_category.id = dm.dc |
---|
893 | <xsl:if test="exists($use-profiles)"> |
---|
894 | JOIN |
---|
895 | link_profile_members |
---|
896 | ON |
---|
897 | link_profile_members.dc = core_data_category.id |
---|
898 | JOIN |
---|
899 | core_profile |
---|
900 | ON |
---|
901 | link_profile_members.profile = core_profile.id |
---|
902 | AND |
---|
903 | ( |
---|
904 | <xsl:for-each select="$use-profiles"> |
---|
905 | core_profile.name = '<xsl:value-of select="replace(.,'''','\\''')"/>' |
---|
906 | <xsl:if test="position()!=last()"> |
---|
907 | OR |
---|
908 | </xsl:if> |
---|
909 | </xsl:for-each> |
---|
910 | ) |
---|
911 | </xsl:if> |
---|
912 | <xsl:if test="exists($use-types)"> |
---|
913 | JOIN |
---|
914 | view_dc_type |
---|
915 | ON |
---|
916 | view_dc_type.id = core_data_category.id |
---|
917 | AND |
---|
918 | ( |
---|
919 | <xsl:for-each select="$use-types"> |
---|
920 | view_dc_type.type = '<xsl:value-of select="replace(.,'''','\\''')"/>' |
---|
921 | <xsl:if test="position()!=last()"> |
---|
922 | OR |
---|
923 | </xsl:if> |
---|
924 | </xsl:for-each> |
---|
925 | ) |
---|
926 | </xsl:if> |
---|
927 | <xsl:choose> |
---|
928 | <xsl:when test="$use-scope='public'"> |
---|
929 | WHERE |
---|
930 | core_data_category.private = false |
---|
931 | </xsl:when> |
---|
932 | <xsl:when test="$use-scope='private'"> |
---|
933 | WHERE |
---|
934 | core_data_category.private = true |
---|
935 | </xsl:when> |
---|
936 | </xsl:choose> |
---|
937 | ORDER BY rank DESC |
---|
938 | ; |
---|
939 | </sql> |
---|
940 | </xsl:when> |
---|
941 | <xsl:otherwise> |
---|
942 | <sql/> |
---|
943 | </xsl:otherwise> |
---|
944 | </xsl:choose> |
---|
945 | </xsl:template> |
---|
946 | </xsl:stylesheet> |
---|
947 | </operator> |
---|
948 | <debug>var:accessor-debug</debug> |
---|
949 | <keywords>var:keywords</keywords> |
---|
950 | <language>var:language</language> |
---|
951 | <fields>var:fields</fields> |
---|
952 | <profiles>var:profiles</profiles> |
---|
953 | <scope>var:scope</scope> |
---|
954 | <match>var:match</match> |
---|
955 | <types>var:types</types> |
---|
956 | <target>var:sql</target> |
---|
957 | </instr> |
---|
958 | <accessor-debug> |
---|
959 | <instr> |
---|
960 | <type>copy</type> |
---|
961 | <operand>var:sql</operand> |
---|
962 | <target>ffcpl:/trace/search.sql.xml</target> |
---|
963 | </instr> |
---|
964 | </accessor-debug> |
---|
965 | <instr> |
---|
966 | <type>ISOcat.manage.system.query</type> |
---|
967 | <query>var:sql</query> |
---|
968 | <target>var:result</target> |
---|
969 | </instr> |
---|
970 | <accessor-debug> |
---|
971 | <instr> |
---|
972 | <type>copy</type> |
---|
973 | <operand>var:result</operand> |
---|
974 | <target>ffcpl:/trace/search.sql.result.xml</target> |
---|
975 | </instr> |
---|
976 | </accessor-debug> |
---|
977 | <instr> |
---|
978 | <type>xslt2</type> |
---|
979 | <operand>var:result</operand> |
---|
980 | <operator> |
---|
981 | <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
---|
982 | <xsl:param name="debug" select="'f'"/> |
---|
983 | |
---|
984 | <xsl:param name="keywords"/> |
---|
985 | |
---|
986 | <xsl:template match="row"> |
---|
987 | <dc ref="{id}" rank="{rank}" private="{private}"/> |
---|
988 | </xsl:template> |
---|
989 | |
---|
990 | <xsl:template match="results"> |
---|
991 | <dcs name="search" type="search" key="keywords: {$keywords}"> |
---|
992 | <xsl:apply-templates/> |
---|
993 | </dcs> |
---|
994 | </xsl:template> |
---|
995 | |
---|
996 | <xsl:template match="null|void"> |
---|
997 | <dcs name="search" type="search" key="keywords: {$keywords}"/> |
---|
998 | </xsl:template> |
---|
999 | </xsl:stylesheet> |
---|
1000 | </operator> |
---|
1001 | <debug>var:accessor-debug</debug> |
---|
1002 | <keywords>var:keywords</keywords> |
---|
1003 | <limit>var:limit</limit> |
---|
1004 | <target>var:result</target> |
---|
1005 | </instr> |
---|
1006 | <accessor-debug> |
---|
1007 | <instr> |
---|
1008 | <type>copy</type> |
---|
1009 | <operand>var:result</operand> |
---|
1010 | <target>ffcpl:/trace/search.dcs.xml</target> |
---|
1011 | </instr> |
---|
1012 | </accessor-debug> |
---|
1013 | <accessor-trace name="prune"> |
---|
1014 | <if> |
---|
1015 | <cond> |
---|
1016 | <instr> |
---|
1017 | <type>sloot.xquery</type> |
---|
1018 | <operator> |
---|
1019 | <b>{ |
---|
1020 | if ( |
---|
1021 | $view != 'isocat' |
---|
1022 | or |
---|
1023 | exists($result/dcs/dc[@private='true']) |
---|
1024 | ) |
---|
1025 | then ('t') |
---|
1026 | else ('f') |
---|
1027 | }</b> |
---|
1028 | </operator> |
---|
1029 | <result>var:result</result> |
---|
1030 | <view>var:view</view> |
---|
1031 | <target>this:cond</target> |
---|
1032 | </instr> |
---|
1033 | </cond> |
---|
1034 | <then> |
---|
1035 | <!-- remove DCs which the user doesn't have access to --> |
---|
1036 | <accessor-debug> |
---|
1037 | <instr> |
---|
1038 | <type>sloot.log</type> |
---|
1039 | <operator> |
---|
1040 | <dbg>DBG: view[{string($view)}]</dbg> |
---|
1041 | </operator> |
---|
1042 | <view>var:view</view> |
---|
1043 | </instr> |
---|
1044 | </accessor-debug> |
---|
1045 | <choose> |
---|
1046 | <cond> |
---|
1047 | <instr> |
---|
1048 | <type>sloot.xpath2eval</type> |
---|
1049 | <operand>var:view</operand> |
---|
1050 | <operator> |
---|
1051 | <xpath>.='isocat'</xpath> |
---|
1052 | </operator> |
---|
1053 | <target>this:cond</target> |
---|
1054 | </instr> |
---|
1055 | </cond> |
---|
1056 | <then> |
---|
1057 | <instr> |
---|
1058 | <type>ISOcat.manage.user.all</type> |
---|
1059 | <credentials>var:credentials</credentials> |
---|
1060 | <user>var:user</user> |
---|
1061 | <target>var:access</target> |
---|
1062 | </instr> |
---|
1063 | </then> |
---|
1064 | <else> |
---|
1065 | <instr> |
---|
1066 | <type>ISOcat.manage.user.view</type> |
---|
1067 | <credentials>var:credentials</credentials> |
---|
1068 | <user>var:user</user> |
---|
1069 | <view>var:view</view> |
---|
1070 | <target>var:access</target> |
---|
1071 | </instr> |
---|
1072 | </else> |
---|
1073 | </choose> |
---|
1074 | <instr> |
---|
1075 | <type>sloot.xquery</type> |
---|
1076 | <operator> |
---|
1077 | <xquery> |
---|
1078 | declare variable $result as node() external; |
---|
1079 | declare variable $access as node() external; |
---|
1080 | |
---|
1081 | <dcs name="search" type="search" key="{$result/dcs/@key}"> |
---|
1082 | { |
---|
1083 | for $dc in $result/dcs/dc |
---|
1084 | where exists($access//dc[@ref=$dc/@ref]) |
---|
1085 | return |
---|
1086 | $dc |
---|
1087 | } |
---|
1088 | </dcs> |
---|
1089 | </xquery> |
---|
1090 | </operator> |
---|
1091 | <result>var:result</result> |
---|
1092 | <access>var:access</access> |
---|
1093 | <target>var:result</target> |
---|
1094 | </instr> |
---|
1095 | <accessor-debug> |
---|
1096 | <instr> |
---|
1097 | <type>copy</type> |
---|
1098 | <operand>var:result</operand> |
---|
1099 | <target>ffcpl:/trace/search.sql.result.pruned.xml</target> |
---|
1100 | </instr> |
---|
1101 | </accessor-debug> |
---|
1102 | </then> |
---|
1103 | <else> |
---|
1104 | <instr> |
---|
1105 | <type>sloot.log</type> |
---|
1106 | <operand> |
---|
1107 | <msg>WRN: skipped prune</msg> |
---|
1108 | </operand> |
---|
1109 | </instr> |
---|
1110 | <!-- noop --> |
---|
1111 | <instr> |
---|
1112 | <type>copy</type> |
---|
1113 | <operand> |
---|
1114 | <null/> |
---|
1115 | </operand> |
---|
1116 | <target>var:void</target> |
---|
1117 | </instr> |
---|
1118 | </else> |
---|
1119 | </if> |
---|
1120 | </accessor-trace> |
---|
1121 | </then> |
---|
1122 | <else> |
---|
1123 | <instr> |
---|
1124 | <type>throw</type> |
---|
1125 | <operand> |
---|
1126 | <ex> |
---|
1127 | <id>ISOcat[METHOD NOT ALLOWED]</id> |
---|
1128 | <message>This method isn't allowed to access this resource.</message> |
---|
1129 | </ex> |
---|
1130 | </operand> |
---|
1131 | </instr> |
---|
1132 | </else> |
---|
1133 | </choose> |
---|
1134 | <instr> |
---|
1135 | <type>ISOcat.manage.system.selection</type> |
---|
1136 | <dcs>var:result</dcs> |
---|
1137 | <target>var:selection</target> |
---|
1138 | </instr> |
---|
1139 | <!-- add the search rank to the selection and limit the number of results --> |
---|
1140 | <instr> |
---|
1141 | <type>xslt2</type> |
---|
1142 | <operand>var:result</operand> |
---|
1143 | <operator> |
---|
1144 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:functx="http://www.functx.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
---|
1145 | <xsl:param name="debug" select="'f'"/> |
---|
1146 | <xsl:param name="limit" select="()"/> |
---|
1147 | <xsl:variable name="def-limit" select="100"/> |
---|
1148 | <xsl:variable name="use-limit" as="xs:integer"> |
---|
1149 | <xsl:choose> |
---|
1150 | <xsl:when test="exists($limit) and ($limit castable as xs:integer)"> |
---|
1151 | <xsl:sequence select="$limit cast as xs:integer"/> |
---|
1152 | </xsl:when> |
---|
1153 | <xsl:otherwise> |
---|
1154 | <xsl:sequence select="$def-limit"/> |
---|
1155 | </xsl:otherwise> |
---|
1156 | </xsl:choose> |
---|
1157 | </xsl:variable> |
---|
1158 | <xsl:param name="selection" select="()"/> |
---|
1159 | <xsl:template match="/dcs"> |
---|
1160 | <xsl:if test="$debug='t'"> |
---|
1161 | <xsl:message>DBG:use-limit[<xsl:value-of select="$use-limit"/>]</xsl:message> |
---|
1162 | </xsl:if> |
---|
1163 | <xsl:copy> |
---|
1164 | <xsl:copy-of select="@*"/> |
---|
1165 | <xsl:choose> |
---|
1166 | <xsl:when test="$use-limit gt 0"> |
---|
1167 | <xsl:for-each select="subsequence(dc,1,$use-limit)"> |
---|
1168 | <xsl:copy> |
---|
1169 | <xsl:copy-of select="@rank"/> |
---|
1170 | <xsl:copy-of select="$selection//dc[@ref=current()/@ref]/@*"/> |
---|
1171 | <xsl:copy-of select="$selection//dc[@ref=current()/@ref]/*"/> |
---|
1172 | </xsl:copy> |
---|
1173 | </xsl:for-each> |
---|
1174 | </xsl:when> |
---|
1175 | <xsl:otherwise> |
---|
1176 | <xsl:for-each select="dc"> |
---|
1177 | <xsl:copy> |
---|
1178 | <xsl:copy-of select="@rank"/> |
---|
1179 | <xsl:copy-of select="$selection//dc[@ref=current()/@ref]/@*"/> |
---|
1180 | <xsl:copy-of select="$selection//dc[@ref=current()/@ref]/*"/> |
---|
1181 | </xsl:copy> |
---|
1182 | </xsl:for-each> |
---|
1183 | </xsl:otherwise> |
---|
1184 | </xsl:choose> |
---|
1185 | </xsl:copy> |
---|
1186 | </xsl:template> |
---|
1187 | </xsl:stylesheet> |
---|
1188 | </operator> |
---|
1189 | <debug>var:accessor-debug</debug> |
---|
1190 | <limit>var:limit</limit> |
---|
1191 | <selection>var:selection</selection> |
---|
1192 | <target>this:response</target> |
---|
1193 | </instr> |
---|
1194 | <instr> |
---|
1195 | <type>ISOcat.interface.rest.dcs.representation</type> |
---|
1196 | <dcs>this:response</dcs> |
---|
1197 | <dcs-type> |
---|
1198 | <string>search</string> |
---|
1199 | </dcs-type> |
---|
1200 | <representation>var:representation</representation> |
---|
1201 | <credentials>var:credentials</credentials> |
---|
1202 | <nvp>var:params</nvp> |
---|
1203 | <dcif-suppress> |
---|
1204 | <string>false</string> |
---|
1205 | </dcif-suppress> |
---|
1206 | <target>this:response</target> |
---|
1207 | </instr> |
---|
1208 | </idoc> |
---|
1209 | <exception> |
---|
1210 | <debug/> |
---|
1211 | <trace>ffcpl:/trace/search.exception.xml</trace> |
---|
1212 | <throw/> |
---|
1213 | </exception> |
---|
1214 | <response> |
---|
1215 | <debug>ffcpl:/trace/search.response.xml</debug> |
---|
1216 | </response> |
---|
1217 | </accessor> |
---|