Limit db:get() calls with fuzzy search and XForms

Monday, 8 June 2026 · 3 messages · last reply 24 Jun 2026
LT
Laurent THEVENON8 Jun 2026 16:11 #
Hello, I'm creating forms using XForms and BaseX. For some of them, I need to use a lot of data, so I've set up a search form that loads an XForms instance at every change in the field, from an internal link like this: /xml/persons/search?query=[search field content]. BaseX responds with RESTXQ:
declare     %rest:path('/xml/persons/search')
%rest:produces('application/xml')     %rest:query-param('query',
'{$query}')     function searchPersons($query){         <persons>
       db:get(myBase)//*:persons[ . contains text
{fn:lower-case($query)} using fuzzy]         </persons> };
Although I only enable searches with 3 characters or more, each change to the search field creates a new call to db:get(), which, if I understand correctly, is not recommended. Could using a variable in the RESTXQ file solve this problem ? Something like :
declare variable $project:allPersons := db:get(myBase)//*:persons
and then only using this new var ? If not, how can I avoid to call to much db:get()? Thank you very much for your answers. Regards, Laurent
CG
Christian Grün22 Jun 2026 11:15 #
Hi Laurent, In principle it is completely fine to use db:get. Are you trying to speed up the runtimes of your queries, or do you have other reasons/motivations to revise your code? Cordialement, Christian
Quoted text · Laurent THEVENON · 26 lines
Von: Laurent THEVENON via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> Gesendet: Montag, 8. Juni 2026 16:11 An: basex-talk at mailman.uni-konstanz.de Betreff: [basex-talk] Limit db:get() calls with fuzzy search and XForms Hello, I'm creating forms using XForms and BaseX. For some of them, I need to use a lot of data, so I've set up a search form that loads an XForms instance at every change in the field, from an internal link like this: /xml/persons/search?query=[search field content]. BaseX responds with RESTXQ: declare %rest:path('/xml/persons/search') %rest:produces('application/xml') %rest:query-param('query', '{$query}') function searchPersons($query){ <persons> db:get(myBase)//*:persons[ . contains text {fn:lower-case($query)} using fuzzy] </persons> }; Although I only enable searches with 3 characters or more, each change to the search field creates a new call to db:get(), which, if I understand correctly, is not recommended. Could using a variable in the RESTXQ file solve this problem ? Something like : declare variable $project:allPersons := db:get(myBase)//*:persons and then only using this new var ? If not, how can I avoid to call to much db:get()? Thank you very much for your answers. Regards, Laurent
LT
Laurent THEVENON24 Jun 2026 07:35 #
Hi Christian Yes my goal is to speed up my queries. But I don't a real speed issue, I'm just trying to produce efficient code. And my mind, multiples calls au db:get() wasn't a good pratice. So if it's fine to use db:get() in my case, I don't really have an issue here :) Thanks a lot for you answer Mit freundlichen Grüßen Laurent
Quoted text · Christian Grün · 53 lines
Le 22/06/2026 à 11:15, Christian Grün a écrit : > Hi Laurent, > > In principle it is completely fine to use db:get. > > Are you trying to speed up the runtimes of your queries, or do you have other reasons/motivations to revise your code? > > Cordialement, > Christian > ________________________________________ > > Von: Laurent THEVENON via BaseX-Talk<basex-talk at mailman.uni-konstanz.de> > Gesendet: Montag, 8. Juni 2026 16:11 > An:basex-talk at mailman.uni-konstanz.de > Betreff: [basex-talk] Limit db:get() calls with fuzzy search and XForms > > Hello, > > I'm creating forms using XForms and BaseX. > For some of them, I need to use a lot of data, so I've set up a search form that loads an XForms instance at every change in the field, from an internal link like this: > > /xml/persons/search?query=[search field content]. > > BaseX responds with RESTXQ: > > declare > %rest:path('/xml/persons/search') > %rest:produces('application/xml') > %rest:query-param('query', '{$query}') > function searchPersons($query){ > <persons> > db:get(myBase)//*:persons[ . contains text {fn:lower-case($query)} using fuzzy] > </persons> > }; > > Although I only enable searches with 3 characters or more, each change to the search field creates a new call to db:get(), which, if I understand correctly, is not recommended. > Could using a variable in the RESTXQ file solve this problem ? Something like : > > declare variable $project:allPersons := db:get(myBase)//*:persons > > and then only using this new var ? > > If not, how can I avoid to call to much db:get()? > > Thank you very much for your answers. > > Regards, > > Laurent > > > >

⚡Generated with XQuery