Hello, I'm looking for an efficient means to count the number of files of a
particular type, where each type is defined by multiple file extensions. For
example, how do you determine the total number of audio/video files in your
MarkLogic database? Same question but for images. Ideally, I'd like to ask
admin to run a single XQuery from the CQ interface but fear a timeout as we
have over 1 mln files. I'll offer the following for illustrative purposes. It
doesn't run. Please don't laugh loud enough for me to hear ;) Thank you in
advance for your time and thoughts.
define function get-extension($uri as xs:string)
{
fn:tokenize($uri, "\.")[fn:last()]
}
let $uris-docs := cts:uri-match("*.*", "document", cts:directory-query("/",
"infinity"))
(: Trying to iterate through this large collection once, setting multiple vars.
:)
for $uri in $uris-docs
let $ext := get-extension($uri)
let $uris-av :=
(
return
if ((fn:compare($ext, "avi") = 0) or (fn:compare($ext, "mov") = 0)
or (fn:compare($ext, "mp3") = 0) or (fn:compare($ext, "wav") = 0)
or (fn:compare($ext, "wma") = 0) or (fn:compare($ext, "wmv") = 0)
or (fn:compare($ext, "ra") = 0) or (fn:compare($ext, "fla") = 0)
or (fn:compare($ext, "flv") = 0) or (fn:compare($ext, "swf") = 0))
then $uri else ()
)
let $uris-img :=
(
return
if ((fn:compare($ext, "ico") = 0) or (fn:compare($ext, "gif") = 0)
or (fn:compare($ext, "jpeg") = 0) or (fn:compare($ext, "jpg") = 0)
or (fn:compare($ext, "mpeg") = 0) or (fn:compare($ext, "mpg") = 0)
or (fn:compare($ext, "tiff") = 0) or (fn:compare($ext, "tif") = 0)
or (fn:compare($ext, "png") = 0) or (fn:compare($ext, "bmp") = 0)
or (fn:compare($ext, "dcr") = 0) or (fn:compare($ext, "pcd") = 0))
then $uri else ()
)
return
(
<count-av>{count($uris-av)}</count-av>
<count-img>{count($uris-img)}</count-img>
)
-Brent
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general