[xquery-talk] search hit count

Michael Kay mhk at mhk.me.uk
Thu Jul 20 20:39:28 PDT 2006


You haven't shown a source document, but my guess is that if $entries has
element children called "text", and "classcode", and descendants called
"div1", then the chance of "$entries[.=$keyword]" selecting anything is
quite small, since it is matching on the entire text content of an element
that has children.

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



> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Cindy Girard
> Sent: 20 July 2006 18:43
> To: talk at xquery.com
> Subject: Re[2]: [xquery-talk] search hit count
> 
> 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 
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk



More information about the talk mailing list