gpt4 book ai didi

full-text-search - XQuery 全文搜索混合内容

转载 作者:行者123 更新时间:2023-12-04 07:23:32 24 4
gpt4 key购买 nike

以下是 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>

现在我想要所有那些包含所有单词“departmental”、“enquiry”和“report”的Chap 节点。

到目前为止,我无法使用各种组合来获取它们。我的尝试之一是 -

for $x in ft:search("Docs", ("departmental enquiry report"), map{'mode':='all words'})/ancestor::*:Para
return $x/ancestor::Chap

任何人都可以指导我吗?

最佳答案

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 子句中的 contains 文本表达式将过滤掉所有不包含所有查询词的节点。使用 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

关于full-text-search - XQuery 全文搜索混合内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com