我有一堆在MarkLogic XML数据库的文件。一个文档具有:

<colors>
  <color>red</color>
  <color>red</color>
</colors>

具有多种颜色是没有问题的。具有多种颜色那都是红色的是一个问题。如何找到具有重复数据文件?

有帮助吗?

解决方案

一切MarkLogic返回仅仅是一个节点的序列,因此,我们可以计算整体的序列大小,并比较它不同值的顺序的计数。如果他们不清晰,他们是重复的,你有你的子集。

for $c in doc()//colors
where fn:count($c/color) != fn:count(fn:distinct-values($c/color))
return $c

其他提示

或者你可以完全做出来的索引:)

for $c in doc()//colors很可能对较大的数据集创建的展开的树CACHE 错误。

下面就是攻击这个当数据是巨大的,确保的 URI词汇已开启的,然后添加一个元素范围指数在一个稍微复杂的方法元件的颜色并计算不同颜色具有重复值的某处。然后遍历仅具有一个这种颜色之一,计算的文档中的利益色彩的项目,频率计数的文件。如果你得到一个频率超过1,该文件需要重复数据删除。

let $qn := xs:QName("color")
let $colorsWithItemFreq := cts:element-values($qn, (), ("ascending", "item-order", "item-frequency"))
let $colorsOfInterest := 
    for $color at $i in cts:element-values($qn, (), ("ascending", "item-order", "fragment-frequency"))
    let $fragFrequency := cts:frequency($color)
    let $itemFrequency := cts:frequency($colorsWithItemFreq[$i])
    where $itemFrequency gt $fragFrequency
    return 
        $color

for $uri in cts:uris( (), ("document"), cts:element-value-query($qn, $colorsOfInterest)
let $colorsWithDuplicationInThisDoc :=
    for $color in cts:element-values($qn, (), ("item-frequency"), cts:document-query($uri) )
    where $color = $colorsOfInterest and cts:frequency($color) gt 1
    return
        $color
where fn:count( $colorsWithDuplicationInThisDoc ) gt 1
return
    $uri

希望有所帮助。

有关此XML:

<?xml version="1.0"?>
<colors>
    <color>Red</color>
    <color>Red</color>
    <color>Blue</color>
</colors>

使用本XSD:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method = "text" />  
    <xsl:strip-space elements="*"/>

    <xsl:template match="colors">

        <xsl:for-each select="color">
            <xsl:variable name="node_color" select="text()"/>
            <xsl:variable name="numEntries" select="count(../color[text()=$node_color])"/>
            <xsl:if test="$numEntries &gt; 1">
                <xsl:text>Color value of </xsl:text><xsl:value-of select="."/><xsl:text> has multiple entries &#xa;</xsl:text>      
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

我得到这样的输出:

Color value of Red has multiple entries 
Color value of Red has multiple entries 

这样至少会找到他们,但它会报告重复颜色的每一次出现,不只是每一个重复的颜色。

这应该可以解决问题。我不是太熟悉MarkLogic,所以第一线得到一套文件可能是错误的。这将返回其具有2个或更多具有相同字符串值的色彩元件的所有文档。

for $doc in doc()
let $colors = $doc//color/string(.)
where some $color in $colors
      satisfies count($colors[. = $color] > 1)
return doc()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top