[xquery-talk] search hit count

Cindy Girard clm6u at virginia.edu
Thu Jul 20 16:43:10 PDT 2006


The XML structure is basic TEI. So, to get a more accurate count, I
need to count all p, title, l, hi, etc.. tags that contain the
keyword?

And that will only give me the number of elements, not the number of
times that the keyword appears within the text (for instance, if a p
has three instances, it'll only count once)?

MK> Yes, but it wouldn't tell you much. Since $entries/text contains $keyword,
MK> $entries will also contain keyword.

MK> Michael Kay
MK> 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 19:49
>> To: talk at xquery.com
>> Subject: Re[4]: [xquery-talk] search hit count
>> 
>> 
>> Could I use a contains() in the count()?
>> 
>> MK> You haven't shown a source document, but my guess is that if 
>> MK> $entries has element children called "text", and "classcode", and
>> MK> descendants called "div1", then the chance of 
>> "$entries[.=$keyword]" 
>> MK> selecting anything is quite small, since it is matching on the 
>> MK> entire text content of an element that has children.
>> 
>> MK> Michael Kay
>> MK> 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
>> 
>> 
>> 
>> --
>> - Cindy 
>> 
>> _______________________________________________
>> talk at xquery.com
>> http://xquery.com/mailman/listinfo/talk



-- 
- Cindy 



More information about the talk mailing list