(: Here the actual query commences. This is split into two parts, the first for a Lucene query and the second for an ngram query. :)
(:The query passed to a Luecene query in ft:query is an XML element <query> containing one or two <bool>. The <bool> contain the original query and the transliterated query, as indicated by the user in $query-scripts.:)
let $hitsAll :=
(:If the $query-scope is narrow, query the elements immediately below the lowest div in tei:text and the four major element below tei:teiHeader.:)
for $hit in query:query-default($request?parameters?field, $request?parameters?query, $request?parameters?doc, ())
order by ft:score($hit) descending
return $hit
let $hitCount := count($hitsAll)
let $hits := if ($hitCount > 1000) then subsequence($hitsAll, 1, 1000) else $hitsAll