简体   繁体   中英

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.

I have done this using FLOWER query. But I need this to be done using CTS functions. Please suggest.

For FLOWER query I have tried this:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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