Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 我的xpath查询无法使用范围索引。我做错了什么?_Xml_Indexing_Xquery_Exist Db - Fatal编程技术网

Xml 我的xpath查询无法使用范围索引。我做错了什么?

Xml 我的xpath查询无法使用范围索引。我做错了什么?,xml,indexing,xquery,exist-db,Xml,Indexing,Xquery,Exist Db,我通过其id查找相关元素,该id存储在引用元素的href中,如下所示: let $item := ($doc//(map|question|theory|reading|glossgroup))[@id = $ref/@href] 阅读ExistDB的文档,我非常确定一个简单的索引应该已经足够了,甚至应该是自动生成的。。但是看看分析器,我的查询没有使用任何索引 我甚至试过 let $item := $doc//map[@id = $ref/@href] 并创建了一个id字段为的索引,如下所示

我通过其id查找相关元素,该id存储在引用元素的href中,如下所示:

let $item := ($doc//(map|question|theory|reading|glossgroup))[@id = $ref/@href]
阅读ExistDB的文档,我非常确定一个简单的
索引应该已经足够了,甚至应该是自动生成的。。但是看看分析器,我的查询没有使用任何索引

我甚至试过

let $item := $doc//map[@id = $ref/@href]
并创建了一个id字段为的索引,如下所示


但似乎一切都不起作用

我对ExistDB是个新手。。可能是做错了什么,所以如果有人能给我指出正确的方向:)

XML示例:


...

如果可以,我建议切换到xml:id属性。这是由exist db自动索引的。然后可以删除索引定义,并使用
id()
函数检索元素

范例

$doc/id($ref/@href)
使用fn:id查找xml:id属性

eXist db自动为所有xml:id属性和其他属性编制索引 DTD中声明的类型ID为的属性(如果验证是 启用)。此自动索引由标准id函数使用 并提供了一种快速查找元素的方法。例如
id(“sect1”)/head
通过快速索引查找工作

但是,等效表达式
//section[@xml:id='sect1']/head
将不使用id索引

一些用户报告说,较大的xml:id值会对性能产生负面影响


如果您仍然想坚持使用
@id

使用以下内容创建范围索引:


这将为您提供基本的索引用法

重写查询可能会进一步提高性能(完全优化):


对于任何对我最终选择的解决方案感兴趣的人。不幸的是,列出的答案并没有让我的查询更快,也没有给我一个重写它的好主意

所以我做了这个:

let $item := $doc//map[@id = $ref/@href]
let $item := if ($item) then $item else $doc//question[@id = $ref/@href]
let $item := if ($item) then $item else $doc//theory[@id = $ref/@href]
let $item := if ($item) then $item else $doc//reading[@id = $ref/@href]
let $item := if ($item) then $item else $doc//glossgroup[@id = $ref/@href]
并分别创建了相应的索引

<create qname="map" type="xs:string">
    <field name="map-id" match="@id" type="xs:string" />
</create>
<create qname="question" type="xs:string">
    <field name="question-id" match="@id" type="xs:string" />
</create>
<create qname="theory" type="xs:string">
    <field name="theory-id" match="@id" type="xs:string" />
</create>
<create qname="reading" type="xs:string">
    <field name="reading-id" match="@id" type="xs:string" />
</create>
<create qname="glossgroup" type="xs:string">
    <field name="glossgroup-id" match="@id" type="xs:string" />
</create>

<create qname="map" type="xs:string">
    <field name="map-id" match="@id" type="xs:string" />
</create>
<create qname="question" type="xs:string">
    <field name="question-id" match="@id" type="xs:string" />
</create>
<create qname="theory" type="xs:string">
    <field name="theory-id" match="@id" type="xs:string" />
</create>
<create qname="reading" type="xs:string">
    <field name="reading-id" match="@id" type="xs:string" />
</create>
<create qname="glossgroup" type="xs:string">
    <field name="glossgroup-id" match="@id" type="xs:string" />
</create>