joewiz
1/1/2017 - 1:46 AM

Test eXist range index, comparing string to integer results

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] }
        }
    }