I'm trying to create an author index list for the articles in the whole volume,
which means we may have 20000 articles in one volume, and each article has more
than one author. The author name element structure is : 
<author><surname>..</surname><fname>..</fname><midname>..</midname>
the number of midname can be 0 or more than 1.

since this is the index, the result will include all the articles under the
volume directory, and the important step for me is to create unique author name
list.  but I found this takes very long time:

   let $article := cts:search(/article, 
cts:directory-query("/journal/coden/vol/","infinity"))
   let $author := $article/front/authgrp/author

   for $surname in distinct-values($author/surname),
        $fname in distinct-values( $author[surname=$surname]/fname ),
        $midname in distinct-values( if(fn:exists($author/middlename)  )
                                                     then
                                                           fn:string-join( for
$m in $author[surname = $surname and fname = $fname]/middlename   return
$m/text(),       " ")
                                                     else ()
                                                   )
   return
      <author>
        <surname>{ $surname }</surname>
        <fname>{ $fname }</fname>
         {
           if(fn:empty($midname)) then ()
           else  <midname>{$midname}</midname>
        }
  </author>

So I'm thinking that I can break the surname with starting letters, I did the
following logic: I loop through 26 letters go get result, the problem is: if
just for one letter, it is kind of quick (still about 10 seconds), but with 26
letters, it somehow takes about 8 minutes, it is much better than  the first
solution, but it is still too long for me.

<result>
{
   let $article := cts:search(/article, 
cts:directory-query("/journal/APPLAB/vol_89/","infinity") )

   for $letter in ("a","b","c","d","e","f","g","h","i","j","k","l","m",
                 "n","o","p","q","r","s","t","u","v","w","x","y","z")
   let $author := $article/front/authgrp/author[fn:starts-with(surname,
$letter, "http://marklogic.com/collation//S2"; )]
   return
    for $surname in distinct-values($author/surname),
          $fname in distinct-values( $author[surname=$surname]/fname ),
          $midname in distinct-values( if(fn:exists($author/middlename) )
                                       then
                                         fn:string-join(for $m in
$author[surname = $surname and fname = $fname]/middlename
                                                return $m/text(),
                                                " ")
                                       else ()
                                      )
       return
       <author>
        <surname>{ $surname }</surname>
        <fname>{ $fname }</fname>
        {
           if(fn:empty($midname)) then ()
           else  <midname>{$midname}</midname>
        }
       </author>
   
}
</result>


Does anyone have suggestions how I should deal with it?

also another small problem, I prefer if no midname, no output, but this code
print out the empty node for midname is no midname exists. Can someone tell me
how to avoid printing out the empty midname?


Thanks, Helen
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to