以下是 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
and Not的文档jerry
,但需要花费大量时间......大约。45 秒,而前一个花了 10 秒!
我正在使用 BaseX 7.5 XML 数据库。
需要专家对此的评论:)