Dear Yann, Thanks for the observation, for which I have created a GitHub issue [1]. It is definitely the enforceindex option that causes the problem; it seemingly enforces more than expected.
Best, Christian [1] https://github.com/BaseXdb/basex/issues/2442 On Wed, Jun 4, 2025 at 1:39 PM Yann de Thézy <[email protected]> wrote: > Hello, > > I encounter what seems to be a bug with the use of Full Text Index (basex > 11.9). > > I have created a database with FTINDEX (and CASESENS + DIACRITICS). > > When I call once a function in the xquery below, the result is different > than when I call it twice. > > It seems that the whole database is searched in the case of 2 calls which > is not what is expected. > > > > Xquery is : > > declare function local:getHit($documents, $word) { > > (# db:enforceindex #) { > > $documents//*[text() contains text {$word}] > > } > > }; > > > > let $docs := collection() > > let $docsSmall := for $doc in $docs where $doc/book/@category='COOKING' > return $doc > > > > let $a := trace("res 1 : " || count(local:getHit($docsSmall, '2005'))) > > (: uncomment the line below to change getHit result :) > > (: let $a := trace("res 2 : " || count(local:getHit($docsSmall, '2005'))) > :) > > return '' > > > > Result is : > > "res 1 : 1" > > After uncommenting the second call, result is: > > "res 1 : 2" > > "res 2 : 2" > > > > The same with this more simple xquery: > > declare function local:getHit($documents, $word) { > > (# db:enforceindex #) { > > $documents//*[text() contains text {$word}] > > } > > }; > > > > let $docs := collection() > > let $docsSmall := $docs[1] > > > > let $a := trace("res 1 : " || count(local:getHit($docsSmall, '2005'))) > > return '' > > Result is : > > "res 1 : 2" > > ("res 1 : 1" expected) > > > > > > 2 documents are populating this database : > > <book category="COOKING"> > > <title lang="en">Everyday Italian</title> > > <author>Giada De Laurentiis</author> > > <year>2005</year> > > <price>30.00</price> > > </book> > > and > > <book category="CHILDREN"> > > <title lang="en">Harry Potter</title> > > <author>J K. Rowling</author> > > <year>2005</year> > > <price>29.99</price> > > </book> > > > > Best, > Yann > > > > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> > Sans > virus.www.avast.com > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> > <#m_-5899971012538410723_m_4277892911591792556_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> >

