Open djbpitt opened 2 years ago
Oops! I mistyped the workaround. ft:query()
doesn't take the third numerical parameter; that belongs with ft:facets()
. A full working example with the workaround is:
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $hits as element(tei:TEI)+ := collection('/db/apps/pr-app/data/hoax_xml')/tei:TEI[ft:query(., ())]
let $facets := ft:facets($hits, "publisher", 10)
return $facets
Context
Using eXist-db 5.4 snapshot and MacOS installed as dmg.
Describe the bug
The following query correctly returns all facet results:
Specifying a third parameter to
facets()
to limit the number of facets returned produces incorrect results:correctly returns 25. But:
also returns 25, and
returns 22.
Expected behavior
I expect
facets()
to return then
facet items with the highest frequencies (or fewer, if the total number of items is less thann
), wheren
equals the third parameter. That is, I expect 1 item if I specify1
, 10 items if I specify10
, etc.To reproduce
collection.xconf is:
Data is in a private repo (copyright); Joe Wicentowski has access and was able to confirm the behavior.
Workaround
Per Joe’s advice, including the full
collection()
path directly in the expression that uses the index, instead of using a variable, gives the correct behavior:Thoughts
If this behavior reflects an inherent limitation of the optimizer (rather than a bug that can be fixed), it would be helpful to document it. The issue is not only that optimization is not performed; in this case the result returned by the expression is incorrect.