Hi Christian,
This weekend I tried to make a query which counts the number of times a certain combination of terms occurs in my repository of xml-files.
I didn't succeed in finding a way to count the number of occurrences. Could you help me with this?
I have attached the result-file from the query to this mail.
As you have said in your last mail, the found letters have to be put in a sequence. After that the items in the sequence have to be counted.
I was thinking of a method like:
let $sequence := ( a method to get the items from the result)
let $count := count($sequence)
return <results> <count>{$count}</count> <items> {for $item in $sequence return <item>{$item}</item> } </items> </results>
let $range := 1 to 800 for $doc in collection('brievenvangogh') let $uri := base-uri($doc), $num := substring($uri, string-length($uri) - 6, 3) where $num castable as xs:integer and xs:integer($num) = $range return <document uri='{$uri}'>{
for $n score $s in $doc//*[text() contains text {'gauguin','pissarro'}all ] return <hit score='{ $s }'>{ $n, count($n) }</hit> } </document>
In my count($n) I get only the number 1.
Thank you very much in advance!
Regards,
Wiard
2011/5/20 Wiard Vasen wiard.vasen@gmail.com
Oke Christian,
I learned a lot from you. Have a nice weekend.
Regards,
Wiard
2011/5/20 Christian Grün christian.gruen@gmail.com
XQuery is a functional language; as such, you can never update variables that have already been assigned. The count() function gives you the number of items in a sequence:
<hit score='{ $s }'>{ $n, count($n) }</hit> ___________________________
On Fri, May 20, 2011 at 5:05 PM, Wiard Vasen wiard.vasen@gmail.com wrote:
Hi Christian, I would like to make a counter for the number of documents
containing the
terms from the query. I made one in blue in the following query. let $range := 1 to 800 for $doc in collection('brievenvangogh') let $uri := base-uri($doc), $num := substring($uri, string-length($uri) - 6, 3) where $num castable as xs:integer and xs:integer($num) = $range return <document uri='{$uri}'>{ let $t := 0 for $n score $s in $doc//*[text() contains text
{'gauguin','pissarro'}all
] return $t:=+1; return <hit score='{$s}'>{$n}{$t} }</hit> }
</document> Could you help me make this counter work? Thank you in advance. Regards, Wiard 2011/5/20 Wiard Vasen <wiard.vasen@gmail.com> > > Hi Christian, > The query works. > Thanks a lot! > Regards, > Wiard > > 2011/5/20 Wiard Vasen <wiard.vasen@gmail.com> >> >> You are probably right. >> That would be funny. >> I am going to figure it out. >> Regards. >> >> 2011/5/20 Christian Grün <christian.gruen@gmail.com> >>> >>> > $doc//*[text() contains text {'gauguin','pissarro','monet'}all ] >>> >>> I would assume that none of the text nodes in your document contains >>> all three names. >> >