Skip to content

Instantly share code, notes, and snippets.

@joewiz
Created January 1, 2017 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewiz/777600c9e01a17efb6e4bb4be130756f to your computer and use it in GitHub Desktop.
Save joewiz/777600c9e01a17efb6e4bb4be130756f to your computer and use it in GitHub Desktop.
Test eXist range index, comparing string to integer results
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
(: setup :)
let $login := xmldb:login('/db', 'admin', '')
let $test1-col := xmldb:create-collection('/db', 'test1')
let $test1-config-col := xmldb:create-collection('/db/system/config/db', 'test1')
let $test2-col := xmldb:create-collection('/db', 'test2')
let $test2-config-col := xmldb:create-collection('/db/system/config/db', 'test2')
let $test1-xconf :=
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index xmlns:xs="http://www.w3.org/2001/XMLSchema">
<range>
<create qname="@notBefore" type="xs:string"/>
</range>
</index>
</collection>
let $test2-xconf :=
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index xmlns:xs="http://www.w3.org/2001/XMLSchema">
<range>
<create qname="@notBefore" type="xs:integer"/>
</range>
</index>
</collection>
let $store-xconfs :=
(
xmldb:store($test1-config-col, 'collection.xconf', $test1-xconf),
xmldb:store($test2-config-col, 'collection.xconf', $test2-xconf)
)
let $doc :=
<origin xmlns="http://www.tei-c.org/ns/1.0">
<origDate notBefore="1438" notAfter="1488">half of 15th century</origDate>
</origin>
let $doc1 := xmldb:store($test1-col, 'doc.xml', $doc)
let $doc2 := xmldb:store($test2-col, 'doc.xml', $doc)
(: test :)
return
element tests {
element test {
element query { "doc($doc1)//tei:origDate[@notBefore > '20']" },
element result { doc($doc1)//tei:origDate[@notBefore > '20'] }
},
element test {
element query { "doc($doc2)//tei:origDate[@notBefore > '20']" },
element result { doc($doc2)//tei:origDate[@notBefore > '20'] }
},
element test {
element query { "doc($doc2)//tei:origDate[@notBefore > 20]" },
element result { doc($doc2)//tei:origDate[@notBefore > 20] }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment