Get great results on marklogic server

I have an XML document like this.

<Authors> <Author> <name>RN Tagore</name> <book>Gitanjli</book> </Author> <Author> <name>Premchand</name> <book>Panch Parameshvar</book> </Author> <Author> <name>HR Bacchan</name> <book>Madhushala</book> </Author> <Author> <name>Premchand</name> <book>Gaban</book> </Author> <Author> <name>Premchand</name> <book>Nirmala</book> </Author> <Author> <name>Premchand</name> <book>Nirmala</book> </Author> </Authors> 

From the above XML, I need a separate list of author name.
For this I can write a query like

 fn:distinct-values(cts:search(fn:doc()//pa:Author/pa:name,cts:and-query(()))) 

What the above code should do: it will get the result of the authors name, and then the fn: distinct-values ​​() function will filter the individual author name from this result set. For the current scenario, it will work fine, because the data is only in XML 6, but when the data is very high, say 50 lac

 cts:search(fn:doc()//pa:Author/pa:name,cts:and-query(())) 

the above part of the request will throw an XDMP-EXPNTREECACHEFULL exception because we are trying to cache 50 lac elements in memory.
Therefore, you need your help to get only the individual author name using the cts: search or search: search API. I don't want to get the result set first, and then retrieve a single record from this result set with fn: distinct-values ​​() .
Thanks,

+4
source share
2 answers

This issue is addressed in the middle of the Ninja tutorial on the first page of the MarkLogic community website , which I recommend you read.

See http://community.marklogic.com/try/ninja/page7

+5
source

You can do this quickly over a large dataset by setting the range index to name . After that use cts: values ​​() .

 cts:values(cts:element-reference(xs:QName("name"))) 

This code assumes that you are using standard sorting for the index.

Note that when you have a common element name, such as "name", you can use a more precise path pointer. In this case, you can set the path range index to Author / name, then

 cts:values(cts:path-reference(xs:QName("Author/name"))) 

(I assume you are using MarkLogic 7+, and if not, you can use cts: element-values ​​() instead of cts: values ​​().)

+2
source

Source: https://habr.com/ru/post/1411935/


All Articles