xquery version "1.0";
declare namespace pm="http://www.politicalmashup.nl";
declare namespace dc="http://purl.org/dc/elements/1.1/";
declare namespace exist ="http://exist.sourceforge.net/NS/exist";
import module namespace request="http://exist-db.org/xquery/request";
import module namespace session="http://exist-db.org/xquery/session";
import module namespace util="http://exist-db.org/xquery/util";
import module namespace kwic="http://exist-db.org/xquery/kwic";
declare option exist:serialize "method=xhtml media-type=text/html";
(: process-input($I,$D,$L) checks if input $I is safe, and if $L is not empty, if $I in $L, if so it returns the safe query, otherwise the default $D :)
declare function local:process-input($inputName,$default,$admittedInputList)
{
let $rawq := lower-case(xs:string(request:get-parameter($inputName, "")))
let $safeq := replace($rawq, "[&"-*;-`~!@#$%^*()_+-=\[\]\{\}\|';:\.,?(:]", "")
return
if ( string-length($safeq) gt 1 and
(
( not(empty($admittedInputList)) and not(empty($admittedInputList[. = $safeq])) ) (: input is in admitted list :)
or
empty($admittedInputList) (: there is no admitted list :)
)
)
then
$safeq
else
$default
};
declare function local:MakeSnippet($hit,$expanded,$start,$end,$query)
{
{ () (: date :) } {xs:string($hit/ancestor::root//dc:date)}
{() (: spreker met link :) }
{xs:string($hit/@speaker)}:
{ () (: title of the topic linked to the speech :)}
{xs:string($hit/ancestor::topic/@title)}
{() (: snippets for the paragraphs listed between $start and $end with a searchterm, plus a link to that paragraph :) }
{ for $p in ($expanded)[position() ge $start][position() le $end] return
kwic:get-summary($p, ($p/exist:match[contains(lower-case(.),$query)][1]),
)
}
};
declare function local:MakeMaidenSnippet($hit)
{
{ () (: date :) } {xs:string($hit/ancestor::root//dc:date)}
{() (: spreker met link :) }
{xs:string($hit//scene[1]/@title)}:
{ () (: title of the topic linked to the speech :)}
{xs:string($hit/@topic)}
{concat($hit/@house,'.')} {concat("Maidenspeech bevat ",$hit/@number-of-words," woorden in ",$hit/@number-of-paragraphs," alineas.")}
};
(: construct search scope :)
let $scope :=
(
doc('/db/nlparliament/maidenspeeches.xml')//maidenspeech[@speaker]
)
(: construct search query :)
let $query := local:process-input('q','islam',())
let $mpquery := local:process-input('mp','allemaal',())
let $resultMP := if ($mpquery = 'allemaal') then $scope else $scope[contains(@speaker,$mpquery)]
let $result := $resultMP[./maidenspeech//speech[1]//p[contains(.,$query)]]
return
Zoeken in de Handelingen
Zoeken in de Handelingen
{(: first we list the number of results :)
concat(count($result)," result",if (count($result) ne 1) then "aten" else "aat")}
{(: Anne ster dit hele stuk weg, en vergelijk de processing tijd, met wat je daarvoor hebt. Je ziet dat er bijna geen verschil is. De grote kosten zitten dus niet hier maar al in de selectie van de zoekvraag:)
for $hit in $result (: $allhits[position() le 10] :)
(: let $expanded := kwic:expand($hit)//p[exist:match[contains(lower-case(.),$query)]] :) (: we have also matches on other search terms (here the MPname) that we do not want to consider . That's why we filter on containg the query:)
return
local:MakeMaidenSnippet($hit)
(: here should come a button which gives the next hits in this topic :)
}