[英]MarkLogic: search for word in any element apart from specified one(s)
我如何编写cts:query来有效地搜索包含某个单词的文档,除非该单词仅出现在某个元素中。
例如,我想返回包含单词“ dog”的文档,但前提是该单词位于<title>之外的任何元素中。
因此,鉴于这些文件:
<document id="doc-1">
<heading>foo</heading>
<paragraph>foo foo foo</paragraph>
</document>
<document id="doc-2">
<heading>bar dog</heading>
<paragraph>bar bar bar</paragraph>
</document>
<document id="doc-3">
<heading>foo dog</heading>
<paragraph>dog bar bar</paragraph>
</document>
我希望返回文档3。
这有效:
for $i in $doc-set
where( doc($i)//*/text()[contains(normalize-space(lower-case(.)), "dog")]
[not(parent::title)] )
return $i ;
但是很慢
如果您始终要排除title元素,则在Admin UI上转到数据库配置页面,单击Word Query(在左侧),单击Excludes选项卡,然后添加该元素。 然后,该元素将从索引中排除,并且cts:word-query()在此处找不到术语。
对于更灵活的解决方案,请使用cts:not-in-query()函数,也称为“温和不”。
cts:search(
fn:doc(),
cts:not-in-query(
cts:word-query("dog"),
cts:element-word-query(xs:QName("title"), "dog")
)
)
请注意(如cts:not-in-query()页中所述),您需要打开正确的位置索引。 我想为此,您需要打开元素词位置,但要运行一些测试。
使用cts:search
:
cts:search(//document,
cts:element-query((xs:QName('heading'), xs:QName('paragraph')),
cts:word-query('dog', 'case-insensitive')))
另外,您可以创建一个字段索引并使用XPath表达式定义要搜索的内容。
使用cts:search说“父母”是您的根元素
cts:search(fn:doc()/ Parent [name()!='Title'],cts:word-query(“ dog”))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.