在我手动编辑 oXygen 上的文件之前,eXist-db 不会为通过 XQuery 更新插入添加的新记录编制索引 ('seen')
New records added via XQuery update insert are not indexed ('seen') by eXist-db until I manually edit the file on oXygen
我是 运行 eXist-db 3.6.1 on CentOS 7.4.1708 (Core),Java(TM) SE Runtime Environment (build 1.8.0_152-b16)。我希望能够在 persons.xml 结构中的最后一条记录之后添加一条新记录,如下所示:
<person xml:id="pe0472"> [...] </person>
<person xml:id="pe0473"> [...] </person>
我在 app.xql 中的一个函数内有一个 html 表单,通过 editpers.html 中的 data-template
调用它获取数据:
declare function app:newpers($node as node(), $model as map(*), $searchkey as xs:string?)
{
let $surname := doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person[@xml:id=$searchkey]/tei:persName/tei:surname
[...]
return
<div class="container">
<form action="add.html" method="POST">
<div class="form-group">
Surname:<br/>
<input type="text" name="surname" value="{$surname}"/>
[...]
<input class="btn btn-default" type="submit" value="Submit"/>
</div>
</form>
</div>
};
表单的提交发送到 add.html,它通过 data-template
:
引用 app:addpers 函数
declare function app:addpers($node as node(), $model as map(*)) {
let $peid := request:get-parameter('peid', '')
let $surname := request:get-parameter('surname', '')
[...]
let $on-disk := doc(concat($config:app-root, '/input/persons.xml'))
let $insert := update insert
<person xml:id="{$peid}" >
<persName xmlns="http://www.tei-c.org/ns/1.0">
<surname>{$surname}</surname>
[...]
</persName>
</person>
following $on-disk//tei:person[@xml:id][last()]
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Added</title>
</head>
<body>
<div>
<h3>Success!</h3>
</div>
</body>
</html>
};
我收到了很好的消息,如果我在 oXygen 中打开 persons.xml 主文件,我可以看到很好地添加了新记录。尽管如此,它并没有出现在我的网页中,该网页通过此查询显示了所有记录:
declare function app:listPers($node as node(), $model as map(*)) {
for $person in doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person
return
<tr>
<td>{$person/tei:persName/tei:forename}</a></td>
</tr>
};
这显示了所有记录,但不是通过 app:addpers 函数添加的最新记录。刷新浏览器上的缓存,这有助于我更新现有记录的值:
let $update := update value $on-disk//tei:person[@xml:id eq $peid]/tei:persName/tei:surname with $surname
(在我清除缓存之前编辑的记录不会显示)这次没有帮助。
为了在我的前端 (app:listPers) 上显示新记录,我对 oXygen 中的主文件做了一些愚蠢的事情(比如,在任何地方添加和删除一个 space,然后保存它),新记录将神奇地出现在我的浏览器页面上。这是预期的行为吗?我觉得这很令人费解,我想不出还有什么可以尝试解决这个问题的。
我已经在 Firefox 58.0.1 和 Safari 11.0.3 上测试过。
我目前的解决方法是添加一个
<script type="text/javascript">
window.addEventListener('load', function (e) {
window.applicationCache.addEventListener('updateready', function (e) {
window.location.reload(true);
}, false);
console.log("loaded");
}, false);
</script>
到受影响页面的头部,强制重新加载页面,而无需手动进行。
我是 运行 eXist-db 3.6.1 on CentOS 7.4.1708 (Core),Java(TM) SE Runtime Environment (build 1.8.0_152-b16)。我希望能够在 persons.xml 结构中的最后一条记录之后添加一条新记录,如下所示:
<person xml:id="pe0472"> [...] </person>
<person xml:id="pe0473"> [...] </person>
我在 app.xql 中的一个函数内有一个 html 表单,通过 editpers.html 中的 data-template
调用它获取数据:
declare function app:newpers($node as node(), $model as map(*), $searchkey as xs:string?)
{
let $surname := doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person[@xml:id=$searchkey]/tei:persName/tei:surname
[...]
return
<div class="container">
<form action="add.html" method="POST">
<div class="form-group">
Surname:<br/>
<input type="text" name="surname" value="{$surname}"/>
[...]
<input class="btn btn-default" type="submit" value="Submit"/>
</div>
</form>
</div>
};
表单的提交发送到 add.html,它通过 data-template
:
declare function app:addpers($node as node(), $model as map(*)) {
let $peid := request:get-parameter('peid', '')
let $surname := request:get-parameter('surname', '')
[...]
let $on-disk := doc(concat($config:app-root, '/input/persons.xml'))
let $insert := update insert
<person xml:id="{$peid}" >
<persName xmlns="http://www.tei-c.org/ns/1.0">
<surname>{$surname}</surname>
[...]
</persName>
</person>
following $on-disk//tei:person[@xml:id][last()]
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Added</title>
</head>
<body>
<div>
<h3>Success!</h3>
</div>
</body>
</html>
};
我收到了很好的消息,如果我在 oXygen 中打开 persons.xml 主文件,我可以看到很好地添加了新记录。尽管如此,它并没有出现在我的网页中,该网页通过此查询显示了所有记录:
declare function app:listPers($node as node(), $model as map(*)) {
for $person in doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person
return
<tr>
<td>{$person/tei:persName/tei:forename}</a></td>
</tr>
};
这显示了所有记录,但不是通过 app:addpers 函数添加的最新记录。刷新浏览器上的缓存,这有助于我更新现有记录的值:
let $update := update value $on-disk//tei:person[@xml:id eq $peid]/tei:persName/tei:surname with $surname
(在我清除缓存之前编辑的记录不会显示)这次没有帮助。
为了在我的前端 (app:listPers) 上显示新记录,我对 oXygen 中的主文件做了一些愚蠢的事情(比如,在任何地方添加和删除一个 space,然后保存它),新记录将神奇地出现在我的浏览器页面上。这是预期的行为吗?我觉得这很令人费解,我想不出还有什么可以尝试解决这个问题的。
我已经在 Firefox 58.0.1 和 Safari 11.0.3 上测试过。
我目前的解决方法是添加一个
<script type="text/javascript">
window.addEventListener('load', function (e) {
window.applicationCache.addEventListener('updateready', function (e) {
window.location.reload(true);
}, false);
console.log("loaded");
}, false);
</script>
到受影响页面的头部,强制重新加载页面,而无需手动进行。