gpt4 book ai didi

full-text-search - 使用 Word1 而非 Word2 进行 XQuery 全文搜索

转载 作者:行者123 更新时间:2023-12-01 01:11:59 25 4
gpt4 key购买 nike

以下是 XML 结构 -

<Docs>
<Doc>
<Name>Doc 1</Name>
<Notes>
<specialNote>
This is a special note section.
<B>This B Tag is used for highlighting any text and is optional</B>
<U>This U Tag will underline any text and is optional</U>
<I>This I Tag is used for highlighting any text and is optional</I>
</specialNote>
<generalNote>
<P>
This will store the general notes and might have number of paragraphs. This is para no 1. NO Child Tags here
</P>
<P>
This is para no 2
</P>
</generalNote>
</Notes>
<Desc>
<P>
This is used for Description and might have number of paragraphs. Here too, there will be B, U and I Tags for highlighting the description text and are optional
<B>Bold</B>
<I>Italic</I>
<U>Underline</U>
</P>
<P>
This is description para no 2 with I and U Tags
<I>Italic</I>
<U>Underline</U>
</P>
</Desc>
</Doc>

将有 1000 个 Doc标签。我想给用户一个搜索条件,他可以在那里搜索 WORD1而不是 WORD2 .以下是查询 -
for $x in doc('Documents')/Docs/Doc[Notes/specialNote/text() contains text 'Tom' 
ftand ftnot 'jerry' or
Notes/specialNote/text() contains text 'Tom' ftand ftnot 'jerry' or
Notes/specialNote/B/text() contains text 'Tom' ftand ftnot 'jerry' or
Notes/specialNote/I/text() contains text 'Tom' ftand ftnot 'jerry' or
Notes/specialNote/U/text() contains text 'Tom' ftand ftnot 'jerry' or
Notes/generalNote/P/text() contains text 'Tom' ftand ftnot 'jerry' or
Desc/P/text() contains text 'Tom' ftand ftnot 'jerry' or
Desc/P/B/text() contains text 'Tom' ftand ftnot 'jerry' or
Desc/P/I/text() contains text 'Tom' ftand ftnot 'jerry' or
Desc/P/U/text() contains text 'Tom' ftand ftnot 'jerry']
return $x/Name

这个查询的结果是错误的。我的意思是,结果包含一些带有 Tom 的文档和 jerry .所以我将查询更改为 -
for $x in doc('Documents')/Docs/Doc[. contains text 'Tom' ftand ftnot 'jerry'] 
return $x/Name

这个查询给了我确切的结果,即;只有那些带有 Tom 的文档而不是 jerry ,但需要大量时间......大约。 45 秒,而较早的需要 10 秒!

我正在使用 BaseX 7.5 XML 数据库。

需要专家对此发表评论:)

最佳答案

第一个查询分别测试文档中的每个文本节点,因此 <P><B>Tom</B> and <I>Jerry</I></P>会匹配,因为第一个文本节点包含 Tom 而不是 Jerry。

在第二个查询中,对 Doc 的所有文本内容执行全文搜索。元素就好像它们被连接成一个字符串一样。这不能(目前)由 BaseX's fulltext index 回答,分别为每个文本节点编制索引。

一种解决方案是分别对每个术语执行全文搜索,最后合并结果。这可以分别为每个文本节点完成,因此可以使用索引:

for $x in (doc('Documents')/Docs/Doc[.//text() contains text 'Tom']
except doc('Documents')/Docs/Doc[.//text() contains text 'Jerry'])
return $x/Name

查询优化器使用两个索引访问将上述查询重写为等效的查询:
for $x in (db:fulltext("Documents", "Tom")/ancestor::*:Doc
except db:fulltext("Documents", "Jerry")/ancestor::*:Doc)
return $x/Name

如果需要,您甚至可以调整合并结果的顺序,以保持中间结果较小。

关于full-text-search - 使用 Word1 而非 Word2 进行 XQuery 全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14955164/

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