1

我想在整个 MarkLogic 数据库中搜索包含特定单词的文档(跨元素和属性)。cts:word-query仅适用于元素。如何在 MarkLogic 中实现这一点?

例子:

文件 1。<abc>Data correction query</abc>

文件 2。<element2 state="correction"></element2>

输出- 如果搜索“更正”一词,则应返回上述两个文档/URIS。

包含该单词的可能元素属性集不是固定的,因为它是一个数据校正练习。cts:word-query在不知道属性名称的情况下,是否有任何可能的方法可以将此类搜索扩展到元素之外?

4

1 回答 1

4

Attributes are not included in the universal index, so you can't just use a standard cts:word-query.

You could create a field index with an XPath for the attributes you want to target and word search options enabled. Depending upon the size of your database, it might not be a great idea to use a super-generic XPath like //*/@*, but it is possible.

Assuming you created a field called attr then you could search with a cts:field-word-query like this:

cts:search(doc(), 
  cts:or-query((
    cts:word-query("correction"), 
    cts:field-word-query("attr", "correction")
  ))
)
于 2021-05-10T13:46:08.797 回答