简体   繁体   English

如何使用CTS函数在MarkLogic中匹配空间?

[英]How to match space in MarkLogic using CTS functions?

I need to search those elements who have space " " in their attributes. 我需要搜索其属性中带有空格" "那些元素。

For example: 例如:

<unit href="http:xxxx/unit/2 ">

Suppose above code have space in the last for href attribute. 假设上面的代码在最后一个href属性中有空格。

I have done this using FLOWER query. 我已经使用FLOWER查询完成了此操作。 But I need this to be done using CTS functions. 但是我需要使用CTS函数来完成。 Please suggest. 请提出建议。

For FLOWER query I have tried this: 对于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>

This is working fine. 一切正常。

For CTS I have tried 对于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)

Your query is looking for " " to be the entirety of the value of the attribute. 您的查询正在寻找“”作为属性值的全部。 If you want to look for attributes that contain a space, then you need to use wildcards. 如果要查找包含空格的属性,则需要使用通配符。 However, since there is no indexing of whitespace except for exact value queries (which are by definition not wildcarded), you are not going to get a lot of index support for that query, so you'll need to run this as a filtered search (which you have in your code above) with a lot of false positives. 但是,由于除了精确值查询(按照定义,它们没有通配符)之外没有空白索引,因此您将不会对该查询获得很多索引支持,因此您需要将其作为过滤搜索来运行(您在上面的代码中具有的内容)有很多误报。

You may be better off creating a string range index on the attribute and doing value-match on that. 您最好在属性上创建一个字符串范围索引,然后对该属性进行值匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM