我想计算 XML 文档中单词的出现次数,查询给出实际计数,但它运行缓慢。
只有两个 xml 文件大小(236 KB,155 KB),需要 17 秒才能产生结果。
以下是查询:
let $doc := db:open('test','/ieee/test.xml')
let $tokens := $doc//text()/fn:tokenize(fn:normalize-space(.),'\s')
let $stringtoken := for $x at $pos in $tokens[position() = 1 to fn:last()-1]
let $y := string-join($tokens[position() = $pos to $pos + 1],' ')
return $y
return
<results>
{
for $result in distinct-values($stringtoken)
let $count := count($stringtoken[. = $result])
return
<term word="{$result}" count="{$count}"></term>
}
</results>
在上面的查询中 let $count := count($stringtoken[. = $result]) 花费了太多时间。
任何提高代码性能的建议都非常感谢。