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




On Wed, Jun 4, 2025 at 1:39 PM Yann de Thézy <yann.dethezy@gmail.com> 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


Sans virus.www.avast.com