1

I need to build a pathRangeQuery for a path with namespace. This is possible in MarkLogic 9 by using the cts.rangeQuery and building a cts.reference. Ex ML9 :

var qname = fn.QName("http://mynamespace.com/example","name");
var elRef = cts.elementReference(qname, ["type=string", "collation=http://marklogic.com/collation/codepoint"]);
var q = cts.rangeQuery(elRef,'>=','myname');

Unfortunately, I can't find the equivalent in MarkLogic 8.

Do you have an idea how to do it ?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Mehdi
  • 67
  • 1
  • 1
  • 9

1 Answers1

2

Correct, cts:range-query and cts.rangeQuery were introduced in MarkLogic 9. In older versions you need to use the more specific range-query functions, like:

http://docs.marklogic.com/8.0/cts.pathRangeQuery

and

http://docs.marklogic.com/8.0/cts.elementRangeQuery

When using namespaces however, the latest note is to use cts.rangeQuery instead of cts.pathRangeQuery. That is not an option with MarkLogic 8. With XQuery, you could have just declared a namespace in your XQuery code, and you would have been good, but that is not an option in SJS either.

You'll need to declare the namespace on app-server or group level to make it work in MarkLogic 8.

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
  • Ok, but how to create a pathRangeQuery on an element with a namespace. The $path-expression is a string so I can't write book/myns:name such as myns is http://mynamespace.com/example ? – Mehdi Jan 25 '18 at 10:29
  • You typically predefine `path-namespaces` on the server, and then use the exact same `path-expression` string as in the index configuration. – grtjn Jan 25 '18 at 10:36
  • I've configured my DB as follows : 1- in path namespaces, I added a ns : - prefix: myns - namespace uri: http://mynamespace.com/example 2- in range path indexes, I added an index - type: string, - path expression : myns:book/myns:name - collation : http://marklogic.com/collation/ 3- The js statement `var rq = cts.pathRangeQuery("myns:book/myns:name","=","xxx");` return an error **[javascript] XDMP-UNBPRFX: var rq = cts.pathRangeQuery("myns:book/myns:name","=" -- Prefix myns has no namespace binding** – Mehdi Jan 25 '18 at 11:07
  • It is the bit about `When using namespaces however ...`. Try reloading the page if you don't see it. – grtjn Jan 28 '18 at 18:31
  • Thanks for the answer. So do you mean that, in ML8, there is no way to define a pathRangeQuery with a declared namespace in SJS? – Mehdi Jan 29 '18 at 10:49
  • You cannot pass in namespace declarations into the pathRangeQuery call, but you can still pre-declare the namespaces on MarkLogic itself to make it work. Just declare them on server or group level, rather than database. The only catch is that you need to use a prefix know to the server, but that shouldn't be a big hurdle.. – grtjn Jan 29 '18 at 11:24
  • Thanks, it works with the NS declaration server side . – Mehdi Jan 30 '18 at 18:54