[英]How to match space in MarkLogic using CTS functions?
我需要搜索其屬性中帶有空格" "
那些元素。
例如:
<unit href="http:xxxx/unit/2 ">
假設上面的代碼在最后一個href屬性中有空格。
我已經使用FLOWER
查詢完成了此操作。 但是我需要使用CTS函數來完成。 請提出建議。
對於FLOWER
查詢,我嘗試了以下方法:
let $x := (
for $d in doc()
order by $d//id
return
for $attribute in data($d//@href)
return
if (fn:contains($attribute," ")) then
<td>{(concat( "id = " , $d//id) ,", data =", $attribute)}</td>
else ()
)
return <tr>{$x}</tr>
一切正常。
對於CTS
我嘗試過
let $query :=
cts:element-attribute-value-query(xs:QName("methodology"),
xs:QName("href"),
xs:string(" "),
"wildcarded")
let $search := cts:search(doc(), $query)
return fn:count($search)
您的查詢正在尋找“”作為屬性值的全部。 如果要查找包含空格的屬性,則需要使用通配符。 但是,由於除了精確值查詢(按照定義,它們沒有通配符)之外沒有空白索引,因此您將不會對該查詢獲得很多索引支持,因此您需要將其作為過濾搜索來運行(您在上面的代碼中具有的內容)有很多誤報。
您最好在屬性上創建一個字符串范圍索引,然后對該屬性進行值匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.