简体   繁体   English

当特定元素在Marklogic中多次出现时,仅搜索那些XML

[英]Search only those XMLs when a particular element occurs multiple times in Marklogic

I am trying to search for document XMLs in Marklogic which have the elements <document> more than once. 我试图在Marklogic中多次搜索包含元素<document>文档XML。 Following is the structure of one such document XML i want to retrieve: 以下是我要检索的一个这样的文档XML的结构:

<root>
    <documents>
        <document>
            <id>1</id>
            <name>roy</name>
            <otherData></otherData>
        </document>
        <document>
            <id>2</id>
            <name>roy</name>
            <otherData></otherData>
        </document>
        ....
        ...
        ..
        .
        <document>
            <id>3</id>
            <name>roy</name>
            <otherData></otherData>
        </document>

    </documents>
</root>

I do not want to retrieve the XMLs which are of the following structure: 我不想检索具有以下结构的XML:

<root>
    <documents>
        <document>
            <id>3</id>
            <name>roy</name>
            <otherData></otherData>
        </document>
    </documents>
</root>

I can search for existence or minimum one using element-query with xs:QName("document") , but not sure how to go about searching with more than one. 我可以使用带有xs:QName("document") element-query搜索是否存在或最少一个,但是不确定如何进行多个搜索。

Any help would be much appreciated. 任何帮助将非常感激。

There is no real simple way of doing this that scales well in MarkLogic. 在MarkLogic中,没有真正简单的方法可以很好地进行扩展。 The easiest way out is by enriching the documents, adding a count attribute to the <documents> element, and keeping it up to date each time you touch the document. 最简单的方法是充实文档,在<documents>元素中添加count属性,并在每次触摸文档时保持其最新状态。 You can then do a straight-forward range index on the count attribute, and directly get what you are after. 然后,您可以对count属性进行简单的范围索引,并直接获得所需的内容。

HTH! HTH!

I like the accepted answer but tried to do differently using both cts:search and XPATH. 我喜欢接受的答案,但尝试同时使用cts:search和XPATH做不同的事情。 It is faster than using only XPATH: 它比仅使用XPATH更快:

xquery version "1.0-ml";
let $query1:= cts:element-query(xs:QName("document"),cts:and-query( () )),
$query2:= cts:element-query(xs:QName("documents"),$query1)
return 
for $doc in cts:search(collection(),$query2,("unfiltered")) where count($doc/root/documents/document) > 1  return  $doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM