Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Justin Makeig
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
jmak...@marklogic.com

> On Feb 2, 2016, at 8:50 AM, Ashley Peacock  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: general-boun...@developer.marklogic.com 
> <mailto:general-boun...@developer.marklogic.com> 
> [mailto:general-boun...@developer.marklogic.com 
> <mailto:general-boun...@developer.marklogic.com>] 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  <mailto:apeac...@elevate.co.uk>> 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:  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:   int
> 2016-02-02 14:14:28.322 Info: TaskServer:   
> 2016-02-02 14:14:28.322 Info: TaskServer:   
> 2016-02-02 14:14:28.322 Info: TaskServer:   localname
> 2016-02-02 14:14:28.322 Info: TaskServer:   
> true
> 2016-02-02 14:14:28.322 Info: TaskServer:   
> ignore
> 2016-02-02 14:14:28.322 Info: TaskServer: 
>  
> 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.
> 
> 
>  
> 
> 
> 
> 
> Ashley Peacock
> 
> Developer II
> Elevate Credit International Limited
> P: 01284 717800 

Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Ashley Peacock
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: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] 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 
mailto:apeac...@elevate.co.uk>> 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: http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://marklogic.com/xdmp/database";>
2016-02-02 14:14:28.322 Info: TaskServer:   int
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   localname
2016-02-02 14:14:28.322 Info: TaskServer:   
true
2016-02-02 14:14:28.322 Info: TaskServer:   
ignore
2016-02-02 14:14:28.322 Info: TaskServer: 

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



Click 
here<https://www.mailcontrol.com/sr/YxyAmhc2!bzGX2PQPOmvUhkLFoJbzkFEjyrqhuh9QPViZjnwTtxSFEksa2wfyPQswHpDQtigvFDaNxM9hG2QrA==>
 to report this email as spam.



[cid:image5008cf.PNG@ac377f03.4384257f]


[cid:image18eced.PNG@64506a28.4693c889]


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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Ashley Peacock
Hi Peter,

Thanks for the reply. When I try that code, I get:

XDMP-UNBPRFX: (err:XPST0081) Prefix db has no namespace 
binding

Any ideas?

Thanks,

Ashley




[cid:image818465.PNG@81d95e71.44a37a73]


[cid:image5e5b83.PNG@18d0fd5d.4ab2e691]


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


From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Peter Kester
Sent: 02 February 2016 16:41
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

Hi Ashley,

Try this:
xquery version "1.0-ml";
declare namespace db = "http://marklogic.com/xdmp/database";;
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";

let $seq := ()
let $indexes := 
admin:database-get-range-element-indexes(admin:get-configuration(), 
xdmp:database("BIR-rest-content"))
let $seq :=
for $i in $indexes
return (
 view:column($i/db:localname/text(), 
cts:element-reference(xs:QName($i/db:localname/text()

return $seq


HTH
Peter

From: 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of Ashley Peacock 
mailto:apeac...@elevate.co.uk>>
Reply-To: MarkLogic Developer Discussion 
mailto:general@developer.marklogic.com>>
Date: Tuesday 2 February 2016 16:55
To: "general@developer.marklogic.com<mailto:general@developer.marklogic.com>" 
mailto:general@developer.marklogic.com>>
Subject: [MarkLogic Dev General] Dynamically Create View Based On Indexes

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: http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://marklogic.com/xdmp/database";<http://marklogic.com/xdmp/database%22>>
2016-02-02 14:14:28.322 Info: TaskServer:   int
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   localname
2016-02-02 14:14:28.322 Info: TaskServer:   
true
2016-02-02 14:14:28.322 Info: TaskServer:   
ignore
2016-02-02 14:14:28.322 Info: TaskServer: 

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).

Does anyone have any ideas?

Thanks,

Ashley



[cid:image001.jpg@01D15DD9.9F122D30]


[cid:image002.png@01D15DD9.9F122D30]


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




Click 
here<https://www.mailcontrol.com/sr/+S6suPqdY8XGX2PQPOmvUg0KooX!PhOyxcKI+jeB832L7gfUXjQAilsnEZCfbOQIwHpDQtigvFDaNxM9hG2QrA==>
 to report this email as spam.
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Christopher Hamlin
On Tue, Feb 2, 2016 at 10:55 AM, Ashley Peacock 
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: http://www.w3.org/2001/XMLSchema-instance"; xmlns="
> http://marklogic.com/xdmp/database";>
>
> 2016-02-02 14:14:28.322 Info: TaskServer:   int
>
> 2016-02-02 14:14:28.322 Info: TaskServer:   
>
> 2016-02-02 14:14:28.322 Info: TaskServer:   
>
> 2016-02-02 14:14:28.322 Info: TaskServer:
> localname
>
> 2016-02-02 14:14:28.322 Info: TaskServer:
> true
>
> 2016-02-02 14:14:28.322 Info: TaskServer:
> ignore
>
> 2016-02-02 14:14:28.322 Info: TaskServer: 
>
>
>
> 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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Peter Kester
Hi Ashley,

Try this:
xquery version "1.0-ml";
declare namespace db = "http://marklogic.com/xdmp/database";;
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";

let $seq := ()
let $indexes := 
admin:database-get-range-element-indexes(admin:get-configuration(), 
xdmp:database("BIR-rest-content"))
let $seq :=
for $i in $indexes
return (
 view:column($i/db:localname/text(), 
cts:element-reference(xs:QName($i/db:localname/text()

return $seq


HTH
Peter

From: 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of Ashley Peacock 
mailto:apeac...@elevate.co.uk>>
Reply-To: MarkLogic Developer Discussion 
mailto:general@developer.marklogic.com>>
Date: Tuesday 2 February 2016 16:55
To: "general@developer.marklogic.com<mailto:general@developer.marklogic.com>" 
mailto:general@developer.marklogic.com>>
Subject: [MarkLogic Dev General] Dynamically Create View Based On Indexes

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: http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://marklogic.com/xdmp/database";>
2016-02-02 14:14:28.322 Info: TaskServer:   int
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   localname
2016-02-02 14:14:28.322 Info: TaskServer:   
true
2016-02-02 14:14:28.322 Info: TaskServer:   
ignore
2016-02-02 14:14:28.322 Info: TaskServer: 

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).

Does anyone have any ideas?

Thanks,

Ashley



[cid:image00cf00.PNG@90d89839.49819056]


[cid:image17a6f7.PNG@fe3cb486.40bd32e5]


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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] Dynamically Create View Based On Indexes

2016-02-02 Thread Ashley Peacock
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: http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://marklogic.com/xdmp/database";>
2016-02-02 14:14:28.322 Info: TaskServer:   int
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   
2016-02-02 14:14:28.322 Info: TaskServer:   localname
2016-02-02 14:14:28.322 Info: TaskServer:   
true
2016-02-02 14:14:28.322 Info: TaskServer:   
ignore
2016-02-02 14:14:28.322 Info: TaskServer: 

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).

Does anyone have any ideas?

Thanks,

Ashley



[cid:image00cf00.PNG@90d89839.49819056]


[cid:image17a6f7.PNG@fe3cb486.40bd32e5]


Ashley Peacock


Developer II
Elevate Credit International Limited
P: 01284 717800 | Ext: 877 |  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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general