Commit 99f0aaf2 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

optimized performance for entity lookup

parent 55f3e12d
......@@ -551,50 +551,63 @@ as element(xhtml:li)* {
(:~ renewed version of the linking function
: generates a XHTML list with all links without using the tei:link[@corresp]
: from the entity. it queries the database for what is really mentioned.
: @version 2.0
:)
declare function ixp:links-new($entity as element()) {
let $id := string($entity/@xml:id)
let $prefix := ixp:get-prefix-by-entity($entity)
let $reference := $prefix || ":" || $id
let $mentions := $ixp:dataCollection//tei:rs[contains(@ref, $reference)][not(@prev)]
let $countOverAll := count($mentions)
let $base-uris := ($mentions ! base-uri()) => distinct-values()
let $countNotebooks := count($base-uris)
let $id := string($entity/@xml:id)
let $prefix := ixp:get-prefix-by-entity($entity)
let $reference := $prefix || ":" || $id
let $hits := $ixp:dataCollection//tei:rs[contains(@ref, $reference)][not(@prev)]
let $array :=
array{
for $hit in $hits
let $base := $hit/base-uri()
let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()]
let $resolve := ixp:resolve-name($tguri)
return
map{
"base": $base,
"tguri" : $tguri,
"title" : $resolve,
"surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n)
}
}
let $titles := $array?*?title => distinct-values()
let $countNotebooks := count($titles)
return
element xhtml:li {
attribute class { "links" },
if($countNotebooks = 1) then 'In Notizbuch' else ('In den Notizbüchern ',
<span style="color:gray">({$countNotebooks} Notizbücher, insgesamt {$countOverAll} Vorkommnisse)</span>),
element xhtml:ul {
element xhtml:li {
attribute class { "links" },
if($countNotebooks = 1) then 'In Notizbuch' else ('In den Notizbüchern ',
<span style="color:gray">({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)</span>),
element xhtml:ul {
(: main list :)
for $uri in $base-uris
let $doc := doc($uri)
let $pageList := $doc//tei:rs[contains(@ref, $reference)][not(@prev)]/ancestor::tei:surface[parent::tei:sourceDoc]
let $tguri := ($uri => tokenize("/"))[last()]
let $resolve := ixp:resolve-name(substring-before($tguri, ".xml"))
let $name := $resolve => replace("([A-E])0(\d)", "$1$2")
order by $resolve
return
element xhtml:li {
$name || ": ",
element xhtml:ul {
attribute class {"link-list-horizontal"},
for $surface in $pageList
let $count := count( $surface//tei:rs[contains(@ref, $reference)][not(@prev)] )
return
element xhtml:li {
for $title in $titles
let $titleArray := $array?*[?title = $title]
let $titleReadable := $title => replace("([A-E])0(\d)", "$1$2")
let $tguri := $titleArray?tguri[1]
order by $title
return
element xhtml:li {
$titleReadable || ": ",
element xhtml:ul {
attribute class {"link-list-horizontal"},
for $surface in distinct-values($titleArray?surface)
let $count := $titleArray[?surface = $surface] => count()
return
element xhtml:li {
element xhtml:a {
attribute href {
"edition.html?id=%2Fxml%2Fdata%2F" || $tguri
|| "&amp;page=" || string($surface/@n)
|| "&amp;page=" || $surface
|| "&amp;target=" || $id
},
f-misc:n-translate(string($surface/@n)),
($surface),
if($count eq 1) then ()
else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
}
}
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment