以下是XML结构-(我在整个文档中给出了一小部分数据。我有一个6 GB的XML,带有适当的全文索引。)
<Docs>
<Doc>
<Chap>No - 1</Chap>
<Desc>
<Notes>
<Para t="sn">departmental report</Para>
</Notes>
<Notes>
<Para t="sn">The equiry commission is good.</Para>
</Notes>
<Notes>
<Para t="sn">departmental process</Para>
<Para t="ln">The enquiry report for the bomb blast is yet to come.<bL/>
<bL/>The department working on this is quite lazy.</Para>
</Notes>
</Desc>
</Doc>
<Doc>
<Chap>No - 2</Chap>
<Desc>
<Notes>
<Para t="sn">Enquiry Processes Report</Para>
<Para t="ln">The enquiry process is very simple.<bL/>
<bL/>With proper guidance anybody can handle the commission easily.<bL/>
<bL/>
</Para>
</Notes>
<Notes>
<Para t="sn">Enquiry - Departmental</Para>
</Notes>
</Desc>
</Doc>
<Doc>
<Chap>No - 3</Chap>
<Desc>
<Notes>
<Para t="sn">Physics Department</Para>
</Notes>
<Notes>
<Para t="sn">Working process of physics department is quite lengthy</Para>
<Para t="ln">Even after proper enquiry, I was told nothing.<bL/>
<bL/>This was like a bomb blast.</Para>
</Notes>
<Notes>
<Para t="sn">Departmental enquiry.</Para>
<Para t="ln">There should be a departmental enquiry for this wrong process.</Para>
</Notes>
</Desc>
</Doc>
</Docs>现在,我希望所有这些Chap节点都包含所有单词“部门”、“查询”和“报告”。
到目前为止,我无法让他们使用各种组合。我的尝试之一是-
for $x in ft:search("Docs", ("departmental enquiry report"), map{'mode':='all words'})/ancestor::*:Para
return $x/ancestor::Chap有人能指点我吗?
发布于 2014-02-27 09:29:50
BaseX的全文索引引用文本节点级别上的所有术语.这意味着您的所有单词都需要出现在同一个文本节点中。
如果要利用全文查询并查找某个元素下面的所有单词,可以尝试以下查询:
let $words := ("departmental enquiry report")
for $doc in db:open("Docs")//Doc[.//text() contains text { $words } any word]
where $doc[string-join(.//text(), ' ') contains text { $words } all words]
return $doc/Chap第一个contains text表达式将被重写为索引请求。它将返回所有返回任何搜索词的文本。where子句中包含的文本表达式将筛选出不包含所有查询项的所有节点。使用string-join(.//text(), ' '),Doc元素下面的所有文本节点都将连接起来,搜索将在连接的字符串上执行。
查询的折页、等效表示应产生相同的结果:
let $words := ("departmental enquiry report")
for $x in ft:search("Docs", $words, map { 'mode': 'any word' })/ancestor::*:Doc
where ft:contains(string-join($x//text(), ' '), $words, map { 'mode': 'all words' })
return $x/Chap发布于 2014-02-27 09:09:23
ft:search,以及为什么它不能解决这个问题
通过查看BaseX‘XQuery全文文档,您将意识到ft:search中的第二个参数应该是一个单词序列:
ft:search($db as xs:string, $terms as item()*, $options as item()) as text()*所以,您的查询应该类似于
for $x in ft:search("Docs", ("departmental", "enquiry", "report"), map{'mode':='all words'})/ancestor::*:Para
return $x/ancestor::Chap但是这仍然不能解决你的问题,因为这个功能
从包含指定
$terms的数据库$terms的全文索引中返回所有文本节点。
换句话说:所有这些单词都必须发生在单个文本节点中,但它们分布在示例输入中的多个文本中(全部分布在<Doc/>节点上)。
使用标准XQuery全文
我不得不从您正在搜索的输入和单词中猜测,您实际上希望搜索包含所有这三个单词的<Doc/>节点。
for $document in doc("Docs")/Docs/Doc
where $document contains text { 'departmental', 'enquiry', 'report' } all words
return $document/Chap这将检索所有文档,对其应用全文搜索,最后返回文档的章节节点。
注意
https://stackoverflow.com/questions/22062779
复制相似问题