Skip to content

Commit 8111bd7

Browse files
authored
Merge pull request Edirom#427 from Edirom/speed-up-getAnnotations
speed improvement for getAnnotationsOnPage
2 parents a282ca7 + a110047 commit 8111bd7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

add/data/xql/getAnnotationsOnPage.xql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ declare function local:findAnnotations($edition as xs:string, $uri as xs:string,
107107

108108
(: TODO: search in other documents and in other collections :)
109109
(: TODO: check if annotations hold URIs or IDRefs :)
110-
functx:distinct-deep(
110+
let $annots := collection(eutil:getPreference('edition_path', $edition))//mei:annot
111+
let $ret :=
111112
for $id in $elemIds
112113

113114
let $uriPlusId := concat($uri, '#', $id)
114115

115116
let $hashId := '#' || $id
116117

117118
(: all mei:annot elements in the editions 'edition_path' collection :)
118-
let $annots := collection(eutil:getPreference('edition_path', $edition))//mei:annot
119119

120120
return
121121
(:
@@ -124,7 +124,7 @@ declare function local:findAnnotations($edition as xs:string, $uri as xs:string,
124124
:)
125125
$annots[contains(@plist, $uriPlusId)][$uriPlusId = tokenize(@plist, '\s')] |
126126
$annots[contains(@plist, $hashId)][$hashId = tokenize(@plist, '\s')]
127-
)
127+
return functx:distinct-deep($ret)
128128
};
129129

130130
(:~
@@ -232,7 +232,11 @@ let $measureLike :=
232232
for $id in $zones[@type = 'measure' or @type = 'staff']/string(@xml:id)
233233
let $ref := concat('#', $id)
234234
return
235-
$mei//*[$ref = tokenize(@facs, '\s')]
235+
(:
236+
: The first predicate with `contains` is just a rough estimate to narrow down the result set.
237+
: It uses the index and is fast while the second (exact) predicate is generally too slow
238+
:)
239+
$mei//*[contains(@facs, $ref)][$ref = tokenize(@facs, '\s+')]
236240

237241
let $svgLike := $surface//svg:svg
238242

0 commit comments

Comments
 (0)