[MarkLogic Dev General] rest search using range index

Paul M pjmaip at yahoo.com
Mon Mar 30 07:57:40 PDT 2015

Yes, see the error. Please delete.
      From: "general-request at developer.marklogic.com" <general-request at developer.marklogic.com>
 To: general at developer.marklogic.com 
 Sent: Monday, March 30, 2015 10:55 AM
 Subject: General Digest, Vol 129, Issue 66
Send General mailing list submissions to
    general at developer.marklogic.com

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
    general-request at developer.marklogic.com

You can reach the person managing the list at
    general-owner at developer.marklogic.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of General digest..."

Today's Topics:

  1. Re: fn:error (Murray, Gregory)
  2. Re: Data profiling on large datasets (Gary Vidal)
  3. rest search using range index (Paul M)


Message: 1
Date: Mon, 30 Mar 2015 12:52:26 +0000
From: "Murray, Gregory" <gregory.murray at ptsem.edu>
Subject: Re: [MarkLogic Dev General] fn:error
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <89CB1298-E514-4201-B6F9-596A6426D69F at ptsem.edu>
Content-Type: text/plain; charset="utf-8"

510 is not defined in the HTTP spec, but I believe the function xdmp:set-response-code() will let you set the code to whatever you want:

xdmp:set-response-code(510,"Description of what you mean by 510")

On Mar 30, 2015, at 8:31 AM, Erik Hennum wrote:

Hi, Pragya:

One footnote to Asit's guidance -- if you're extending the REST API, you can throw the RESTAPI-SRVEXERR error to set the HTTP response.

For more, see:


Erik Hennum

From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [general-bounces at developer.marklogic.com] on behalf of Asitmohan Nautiyal [asitmohan.n at hcl.com]
Sent: Monday, March 30, 2015 5:15 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] fn:error

Hi Pragya,

500 response code is coming from MarkLogic predefined error utility file where all response code has been defined as per specific message or standards. You need to change that configuration file manually but its not recommended at all.

You can create your own custom xml file with your custom codes and messages. While throwing the respective error you can return your own customize response.

Asit Nautiyal
From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [general-bounces at developer.marklogic.com] on behalf of Kapoor, Pragya [PKapoor1 at innodata.com]
Sent: Monday, March 30, 2015 4:54 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] fn:error


I am using fn:error as :

if($e//error:code/text() eq "XDMP-LEXVAL") then
    fn:error(xs:QName("ERROR"), "Incorrect Data Entered in Search Query")
else ()

I get a response as :

    <message>Internal Server Error | ERROR - Incorrect Data Entered in Search Query</message>
    <description>Incorrect Data Entered in Search Query (ERROR): in /rest-apis/search/search-document.xqy at line number 616</description>

In my response error code is 500. I need to change the code to some other no say 510.
How can I achieve this?


"This e-mail and any attachments transmitted with it are for the sole use of the intended recipient(s) and may contain confidential , proprietary or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this e-mail or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful."

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150330/9066e82e/attachment-0001.html 


Message: 2
Date: Mon, 30 Mar 2015 13:38:41 +0000
From: Gary Vidal <Gary.Vidal at marklogic.com>
Subject: Re: [MarkLogic Dev General] Data profiling on large datasets
To: "general at developer.marklogic.com"
    <general at developer.marklogic.com>
    <F6CA301823F6334598E3FE5F973EBAE115C12B41 at EXCHG10-BE02.marklogic.com>
Content-Type: text/plain; charset="us-ascii"


I hoisted this code from a project I wrote that does analysis and captures statistics.  The goal is to do recursive descent until all nodes are resolved by appending a query to negate visited root nodes, with a cut-off before tree-cache fills up.  

declare namespace a = "a:roots";
declare variable $bcount := 0;
declare variable $MAX-ITERATIONS := 200;
declare variable $base-constraint := cts:and-query(());

declare function a:get-root-elements($bdone,$qnames,$results) {
  xdmp:set($bcount,$bcount + 1),
  if($bdone or $bcount > $MAX-ITERATIONS) then (
    xdmp:log(fn:concat("Starting Root Frequency:",xdmp:elapsed-time()),"debug"),
    for $k in $results
    let $parts := fn:analyze-string($k,"\{(.*)\}(.*)")
    let $ns := fn:string($parts/*:match/*:group[@nr eq 1])
    let $local-name := fn:string($parts/*:match/*:group[@nr eq 2])
    let $frequency  :=
        if($ns eq "") 
        then xdmp:eval(
            fn:concat("declare variable $base-constraint external;xdmp:estimate(cts:search(/",$local-name,",($base-constraint),('unfiltered')))"),
        else xdmp:eval(
            fn:concat("declare namespace _1  = """,$ns,""";
                      declare variable $base-constraint external;
    where $frequency > 0
    return ((:
    xdmp:log(fn:concat("Finished Root Frequency:",xdmp:elapsed-time()),"debug")
    let $constraint := 
      then for $qn in $qnames return cts:not-query(cts:element-query($qn,cts:and-query(())))
      else ()
    let $rnode :=      
        then fn:subsequence(cts:search(/element(),cts:and-query(($base-constraint,$constraint)),"unfiltered"),1,1)
        else fn:subsequence(cts:search(/element(),cts:and-query(()),"unfiltered"),1,1)
        if($rnode instance of element() and fn:not(fn:node-name($rnode) = $qnames)) 
            let $qname := fn:node-name($rnode)
            let $key := fn:concat("{",fn:namespace-uri($rnode),"}",fn:local-name($rnode))
            return (
        else if(fn:node-name($rnode) = $qnames) then 
        else if(fn:empty($rnode)) then


Message: 3
Date: Mon, 30 Mar 2015 14:54:52 +0000 (UTC)
From: Paul M <pjmaip at yahoo.com>
Subject: [MarkLogic Dev General] rest search using range index
To: "general at developer.marklogic.com"
    <general at developer.marklogic.com>
    <563963243.1238762.1427727292204.JavaMail.yahoo at mail.yahoo.com>
Content-Type: text/plain; charset="utf-8"

This search works as expected when entered in GUI and http server:

? localhost:xxx/?q=kwd%3AAluminium

this works as well using REST:
? localhost:xxx/v1/search?q=Aluminum

this does not work using REST:
Documentation is a bit unclear. Is the last version supposed to work? If not, why not?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150330/2a060f08/attachment.html 


General mailing list
General at developer.marklogic.com

End of General Digest, Vol 129, Issue 66

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150330/1dadfbdf/attachment-0001.html 

More information about the General mailing list