On Tue, Feb 2, 2016 at 10:55 AM, Ashley Peacock <[email protected]> wrote:
> Hey, > > > > I have the basic idea of how to achieve creating a view based on the > current indexes on a field, I just can’t tie all the pieces together so > hoping someone can help! > > > > When calling admin:database-get-range-element-indexes() it returns a bunch > of XML defining the indexes. I want to loop through each index, retrieve > some values (the XML looks something like: > > > > 2016-02-02 14:14:28.322 Info: TaskServer: <range-element-index xmlns:xsi=" > http://www.w3.org/2001/XMLSchema-instance" xmlns=" > http://marklogic.com/xdmp/database"> > > 2016-02-02 14:14:28.322 Info: TaskServer: <scalar-type>int</scalar-type> > > 2016-02-02 14:14:28.322 Info: TaskServer: <collation/> > > 2016-02-02 14:14:28.322 Info: TaskServer: <namespace-uri/> > > 2016-02-02 14:14:28.322 Info: TaskServer: > <localname>localname</localname> > > 2016-02-02 14:14:28.322 Info: TaskServer: > <range-value-positions>true</range-value-positions> > > 2016-02-02 14:14:28.322 Info: TaskServer: > <invalid-values>ignore</invalid-values> > > 2016-02-02 14:14:28.322 Info: TaskServer: </range-element-index> > > > > And store then in a sequence. I’ve tried the below to no luck, as my > XQuery is not the strongest. > > > > Let $seq := () > > For $i in > admin:database-get-range-element-indexes(admin:get-configuration(), > xdmp:database(‘myDatabase’)) > > Return fn:insert-before($seq, 0, > view:column($i/range-element-index/localname, > $i/range-element-index/localname) > > > > But that doesn’t seem to work (there’s no error, it just doesn’t “do” > anything). > > > The insert-before is returning a new sequence each time, so not what you expect (doesn't change $seq). You aren't using the namespace for the index elements either, so wouldn't be finding anything. Something like the below is probably closer. It gets the namespace/localname, tokenizes since you can have more than one, removes a hyphen since that's not allowed in a view column name. Did sort-of work on the simplistic basic db I tested on, but may be more complications. xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; import module namespace view = "http://marklogic.com/xdmp/view" at "/MarkLogic/views.xqy"; declare namespace db = 'http://marklogic.com/xdmp/database'; let $config := admin:get-configuration() let $seq := for $i in admin:database-get-range-element-indexes(admin:get-configuration(), xdmp:database('Documents')) let $namespace-uri := $i/db:namespace-uri/fn:string() for $localname in fn:tokenize ($i/db:localname/fn:string(), '[ ,]+') let $col-name := fn:replace ($localname, '-', '') let $col := view:column($col-name, cts:element-reference (fn:QName ($namespace-uri, $localname))) return $col return $seq It looks like it gives what you want, though I didn't use the results at all. Also, if JS is more natural, you can use that instead. =ch
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
