进入cts的位置:搜索



给定此查询:

for $d in cts:search(
      fn:doc(),
      cts:and-query(
       (            
         cts:collection-query(('InProgress_Audit'))
       )
      ))          
      where not(fn:contains($d//TitleDate/text(),"Z"))
      return <p>{document-uri($d)}</p>

如何将"where"约束移动到CTS搜索查询中?

这使用cts:query来应用约束:

for $d in cts:search(
  fn:doc(),
  cts:and-not-query(            
     cts:collection-query('InProgress_Audit'),
     cts:element-query(xs:QName('TitleDate'),
       cts:word-query('*Z*', 'wildcarded'))
  ))
return <p>{document-uri($d)}</p>

有一些索引选项可以加快通配符搜索。您还可以将TitleDate上的范围索引与cts:element-range-index-query结合使用,以进一步加快速度。

更新:正如@mmblakele在评论中指出的,cts:element-value-query可能比嵌套的cts:element-query/cts:word-query:更快

cts:element-value-query(xs:QName('TitleDate'), '*Z*', 'wildcarded')

使用cts:uris将比多次重复调用document-uri()更快。但是,您需要在设置中启用URI词典选项。把所有这些放在一起,查询看起来像:

cts:uris((), 'document',
  cts:and-not-query((            
     cts:collection-query('InProgress_Audit'),
     cts:element-value-query(xs:QName('TitleDate'), 
       '*Z*', 'wildcarded')
  ))) ! element p { . }

最新更新