The following query gives me no results:
for $city as xs:string in ("Paris", "Cambridge", "London", "Oxford") return ( $city, count(/dictionary/letter/entry[.//p//text() contains text {$city}]), "
" )
However, BaseX rewrites it to
for $city as xs:string in ("Paris", "Cambridge", "London", "Oxford", ...) return ($city, fn:count(db:fulltext("with-sources", { $city })/ancestor::*:p/ancestor::*:entry), " ")
If I remove the braces around $city in the argument to db:fulltext() I get the right answers (or at least plausible answers).
So this looks like a bug in the rewriting engine.
Liam