4

I have a XML document like this.

  <Authors>
      <Author>
        <name>R.N Tagore</name>
        <book>Gitanjli</book>
      </Author>
      <Author>
        <name>Premchand</name>
        <book>Panch Parameshvar</book>
      </Author>
      <Author>
        <name>H.R 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 distinct list of author's 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 will do is, It will get result of Authors name and then fn:distinct-values() function will filter distinct Author name from that result set. For the current scenario it will work fine because data in XML only 6, But when data is very high let say 50 lac's

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

the above portion of query will give XDMP-EXPNTREECACHEFULL Exception because we are trying to cache 50 lac's element in memory.
So need your help to get only distinct author name by using cts:search or search:search API. I don't want to first get a result set and then extract distinct record from that result set by using fn:distinct-values().
Thanks,

4

2 回答 2

5

这个问题在MarkLogic 社区网站首页的 Ninja 教程的中间部分得到了解决,我建议你阅读。

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

于 2012-05-11T14:51:53.990 回答
2

您可以通过在name. 一旦你有了它,使用cts:values()

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

此代码假定您使用索引的默认排序规则。

请注意,当您拥有像“名称”这样的通用元素名称时,您可能希望使用更精确的路径索引。在这种情况下,您可以在 Author/name 上设置路径范围索引,然后

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

(我假设您使用的是 MarkLogic 7+;如果没有,您可以使用cts:element-values()而不是 cts:values()。)

于 2014-12-04T21:49:24.667 回答