Hi Christian,

I think the database you describe looks like this:

<words>
  <word n="1">one</word>
  <word n="2">two</word>
  <word n="3">three</word>
  <word n="4">four</word>
  <word n="5">five</word>
  <word n="6">six</word>
  <word n="7">seven</word>
  <word n="8">eight</word>
  <word n="9">nine</word>
  <word n="10">ten</word>
</words>

So I always use XML for this?  There's no persistent representation of the map data structure? 

Jonathan

On Thu, Mar 24, 2022 at 2:02 PM Christian Grün <christian.gruen@gmail.com> wrote:
Hi Jonathan,

You can create databases that contain key/value pairs:

let $words := <words>{
  for $i in 1 to 10
  return <word n='{ $i }'>{ format-integer($i, 'w') }</word>
}</words>
return db:create('words', $words, 'words.xml')

If you look up values in that database …

for $n in (1 to 10) ! string()
return db:open('words')//word[@n = $n] ! data()

… the text index will be utilized, and your query will be rewritten as follows:

(1 to 10) ! data(db:attribute("words", string(.))/
  self::attribute(n)/parent::word)

If you don’t want to rely on the rewritings of the query optimizer,
you can directly use db:attribute.

Best,
Christian