xquery version "1.0";
declare namespace session="http://exist-db.org/xquery/session";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace util="http://exist-db.org/xquery/util";
declare namespace i18n="http://apache.org/cocoon/i18n/2.1";
import module namespace ristenutil="http://www.risten.no/shared/util" at "../xquery/ristenutil.xqm";
(: Create filter expression from query term, field and mode,
and add a classification filter if specified :)
declare function local:filter-expr($term as xs:string,
$field as xs:string,
$mode as xs:string) as xs:string
{
(: Build the term search expression: :)
let $f := "l", (: This contains the element name to search, can be taken from user input :)
$t := concat("'", $term, "'"), (: add single quotes around the search term :)
$t2 := replace($term,"\?",".?"), (: replace ? with .? :)
$t3 := replace($t2,"\*",".*"), (: replace * with .* :)
$t4 := replace($t3,"\(","\\("), (: escape left parenthesis :)
$t5 := replace($t4,"\)","\\)"), (: escape right parenthesis :)
$ttrad := concat("'^", $t5, "'") (: anchor the search string to each end :)
let $termsearch :=
if ($mode = "trad") then
concat("matches(", $f, ", ", $ttrad, ")")
else if ($mode = "near") then
concat("near(", $f, ", ", $t, ")")
else if ($mode = "exact") then
concat($f, " = ", $t)
else
concat($f, " &= ", $t)
return $termsearch
};
(: Assemble the query string :)
declare function local:build-query($srchcoll as xs:string,
$term as xs:string,
$orderby as xs:string)
as xs:string
{
let $field := request:get-parameter("field", "any"),
$mode := request:get-parameter("mode", "all"),
$expr := local:filter-expr($term, $field, $mode)
return
let $query := concat("for $r in collection('",
$srchcoll,
"')//e[", (: adjust to the name of the element containing the dic article :)
$expr,
"] return ",
"
Your document path: {$srchcoll}
Your $lang string: {$srchlang}
Your session attributes: {$session}
Your query filter/old query:
{$queryOld}
Your document path: {$srchcoll}
Your $lang string: {$srchlang}
Your session attributes: {$session}
Your query filter/old query:
{$queryOld}
Your complete search query:
{$query}
Your document path: {$srchcoll}
Your $lang string: {$srchlang}
Your session attributes: {$session}
Your query filter/old query:
{$queryOld}
Your complete search query:
{$query}
{ round-half-to-even( seconds-from-duration( util:system-time()-$start) , 3)}
) }