You can import XQuery libraries into JavaScript modules and call functions as 
if they were JavaScript: 

'use strict';
var admin = require('/MarkLogic/admin');
var config = admin.getConfiguration();
admin.databaseGetRangeElementIndexes(config, xdmp.database());

Justin


--
Justin Makeig
Director, Product Management
MarkLogic
[email protected]

> On Feb 2, 2016, at 8:50 AM, Ashley Peacock <[email protected]> wrote:
> 
> Thanks for the reply.
>  
> I’d love to use the JS library instead, but I couldn’t find the JS functions 
> that would replicate the ones below – such as 
> admin:database-get-range-element-indexes. Maybe I’m looking in the wrong 
> place?
>  
> Ashley
>  
> From: [email protected] 
> <mailto:[email protected]> 
> [mailto:[email protected] 
> <mailto:[email protected]>] On Behalf Of Christopher 
> Hamlin
> Sent: 02 February 2016 16:43
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes
>  
>  
>  
> On Tue, Feb 2, 2016 at 10:55 AM, Ashley Peacock <[email protected] 
> <mailto:[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 
> <http://www.w3.org/2001/XMLSchema-instance>" 
> xmlns="http://marklogic.com/xdmp/database 
> <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 
> <http://marklogic.com/xdmp/admin>" at "/MarkLogic/admin.xqy";
> import module namespace view = "http://marklogic.com/xdmp/view 
> <http://marklogic.com/xdmp/view>" at "/MarkLogic/views.xqy";
> declare namespace db = 'http://marklogic.com/xdmp/database 
> <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
>  
>  
> 
> Click here 
> <https://www.mailcontrol.com/sr/YxyAmhc2!bzGX2PQPOmvUhkLFoJbzkFEjyrqhuh9QPViZjnwTtxSFEksa2wfyPQswHpDQtigvFDaNxM9hG2QrA==>
>  to report this email as spam.
> 
> 
>  
> <image5008cf.PNG>
> 
> <image18eced.PNG>
> 
> Ashley Peacock
> 
> Developer II
> Elevate Credit International Limited
> P: 01284 717800 | Ext: 877 |  Elevate.co.uk <http://elevate.co.uk/>
> Amadeus House, Floral Street, Covent Garden, London WC2E 9DP
> 
>  
> Privileged and Confidential. This e-mail, and any attachments thereto, is 
> intended only for use by the addressee(s) named herein and may contain 
> privileged and/or confidential information. If you have received this e-mail 
> in error, please notify me immediately by a return e-mail and delete this 
> e-mail. You are hereby notified that any dissemination, distribution or 
> copying of this e-mail and/or any attachments thereto, is strictly 
> prohibited. 
> 
> Elevate Credit International Limited is registered in England & Wales with 
> Company Number 05041905. Registered Office: 27-28 Eastcastle Street, London, 
> W1W 8DH
>  
> _______________________________________________
> General mailing list
> [email protected] <mailto:[email protected]>
> Manage your subscription at: 
> http://developer.marklogic.com/mailman/listinfo/general 
> <http://developer.marklogic.com/mailman/listinfo/general>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to