[xquery-talk] search hit count

Cindy Girard clm6u at virginia.edu
Thu Jul 20 14:43:24 PDT 2006


The count function is nine lines down in the following code. I tried Michael's
suggestion, but I'm not getting any results on the count. What am I
doing wrong?

Thanks,
Cindy

-------------------------------
$hits :=
   for $entries in collection($collctn)//tei.2
      let $docname := concat($entries/@id, '.xml')
      let $divs := $entries//div1
      let $text := $entries/text
        where contains($text, $keyword)
          return
          <doc>{$entries/@id, $entries/@type, <docname>{$docname}</docname>,
            <classcode>{$entries/classcode}</classcode>, <ct>{count($entries[.=$keyword])}</ct>,
                         $entries/teiheader/filedesc/titlestmt/title,  
                <divs>
                            { for $diventries in $entries//div1
                               let $div1s := $diventries
                                    where contains($div1s, $keyword)
                                    return <div>{$diventries/@n, $diventries/head, 
                                    <div2s>
                                       { for $div2ent in $diventries//div2
                                            let $div2s := $div2ent
                                            where contains($div2s, $keyword)
                                            return <div2>{$div2ent/@n, $div2ent/head}</div2>
                                            }</div2s>
                                            }</div>
                            }</divs>}</doc>,

-------------------------------

>>   The count() function give me how
>>   many documents in which the search is found, but not the individual
>>   hit count.

MK> I suspect you did something like 

MK> count($docs[x/y/z='hit'])

MK> which would give you the number of $docs in which x/y/z='hit' is true.

MK> Change this to

MK> count($docs/x/y/z[.='hit'])

MK> and you will get the number of z elements equal to 'hit'.

MK> Michael Kay
MK> http://www.saxonica.com/



-- 
- Cindy 



More information about the talk mailing list