问题描述
我必须认识到我无法获得XQuery查询的逻辑... 所以这是我的问题。
<doc id="book_1"> <title>Title</title> <div type="chapter" id="ch_1"> <head>Chapter 1</head> <p><pb n="1"/> text text text text</p> <p>text text text text</p> <p>text text KEYWORD text text</p> <p><pb n="2"/> text text text text</p> <p>text KEYWORD text text text</p> <p>text text text text</p> <p><pb n="3"/> text text text text</p> <p>text text text text</p> </div> <div type="chapter" id="ch_2"> <head>Chapter 2</head> <p><pb n="4"/> text text text text</p> <p>text text text KEYWORD text</p> <p>text KEYWORD text text text</p> <p><pb n="5"/> text text text text</p> <p>text text text text</p> <p>text text text text</p> <p><pb n="6"/> text text text text</p> <p>text KEYWORD text text text</p> </div> etc. etc. etc. </doc>
@H_502_9@我正在通过此文件寻找“ KEYWORD”,我希望能够在夹心页面(
pb
)上找到每个关键词。我当前的XQuery:
xquery version "3.1"; import module namespace kwic="http://exist-db.org/xquery/kwic"; let $query := <query><bool><term>KEYWORD</term></bool></query> for $hit in collection("my_collection/my_files")//doc[ft:query(.,$query)] let $hit_expanded := kwic:expand($hit) let $book_id := data($hit_expanded//exist:match/ancestor::doc/@id) let $page := data($hit_expanded//exist:match/preceding::pb[1]/@n) return kwic:summarize($hit,<config width="40" link="book_id={$book_id}__page={$page}"/>)
@H_502_9@按照我的逻辑:
i)每次找到“ 查询”时,“ for ”循环将调用“ 返回”;
ii),对于每个找到的查询,我将查找书籍ID( $ book_id ),并查找紧随其后的唯一页数( $ page )。
这就是我得到的:(请注意@href中的页码)
1 <p> <span class="prevIoUs">...text text text </span> <a class="hi" href="book_id=book_1__page=1 2 4 6">KEYWORD</a> <span class="following">text text text...</span> </p> 2 <p> <span class="prevIoUs">...text text text</span> <a class="hi" href="book_id=book_1__page=1 2 4 6">KEYWORD</a> <span class="following"> text text text...</span> </p> 3 <p> <span class="prevIoUs">... text text text </span> <a class="hi" href="book_id=book_1__page=1 2 4 6">KEYWORD</a> <span class="following"> text text text...</span> </p> etc. etc. etc.
@H_502_9@好的,我知道它会重复不同页面的次数“ n ”次(其中 n =在不同页面中找到的关键字数)。 但是为什么呢?我的意思是,i)我们必须处于“ for ”循环中,并且只能按时间获得一个“ query ”结果; ii)我明确地表示仅接受第一个 [1] ,紧接其前,用于 query ”的页面编号...
这是我想要的结果(请注意@href中的页码)
1 <p> <span class="prevIoUs">...text text text </span> <a class="hi" href="book_id=book_1__page=1">KEYWORD</a> <span class="following">text text text...</span> </p> 2 <p> <span class="prevIoUs">...text text text</span> <a class="hi" href="book_id=book_1__page=2">KEYWORD</a> <span class="following"> text text text...</span> </p> 3 <p> <span class="prevIoUs">... text text text </span> <a class="hi" href="book_id=book_1__page=4">KEYWORD</a> <span class="following"> text text text...</span> </p> etc. etc. etc.
@H_502_9@所以,我错过了XQuery查询的逻辑?
编辑:如果我将页码查询直接放在返回上,它什么都不会改变,就像这样:
kwic:summarize($hit,<config width="40" link="book_id={$book_id}__page={data($hit_expanded//exist:match/preceding::pb[1]/@n)}"/>)
@H_502_9@编辑2 :有我的collection.xconf文件:
<collection xmlns="http://exist-db.org/collection-config/1.0"> <index xmlns:kwic="http://exist-db.org/xquery/kwic" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <lucene> <text qname="doc"/> <text qname="div"/> <text qname="p"/> </lucene> </index> </collection>
@H_502_9@解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)