Marklogic 如何在搜索中转义单引号:搜索?

Marklogic 如何在搜索中转义单引号:搜索?,marklogic,marklogic-7,Marklogic,Marklogic 7,我正在使用search:searchAPI 在搜索选项语法中,我将引号用作“”” 定义的约束: <constraint name="pubTitle"> <value> <element ns="" name="pubTitle"/> </value> </constraint> 现在我想在pubTitle元素中搜索文本为'test''pu'b'的文档 我的搜索查询是什么?(search:search

我正在使用
search:search
API

搜索选项语法中,我将引号用作“

定义的约束:

<constraint name="pubTitle">
    <value>
       <element ns="" name="pubTitle"/>
    </value>
</constraint>

现在我想在pubTitle元素中搜索文本为
'test''pu'b'
的文档

我的搜索查询是什么?(
search:search
第一个参数)


救命啊

更新有助于澄清问题。你有单引号的内容

更准确地说,您希望搜索包含单引号、空格甚至函数间的标题。执行值搜索是有意义的,但是传入
search:search
的搜索字符串将被解析。如果不将搜索值或短语括在引号中,解析器将认为该值以下一个空格结尾。如果您没有更改
选项,那么解析器将在
测试之后停止(在您给出的初始示例中)

更改为单引号会使情况变得更糟,因为您的搜索值也包含单引号,并且解析器会混淆它们。如果
search:search
最终以全文形式搜索
test
pub
,这是默认行为,我不会感到惊讶

如果要手动调用
search:search
,双引号也有点棘手。您需要双引号来包装搜索值,但也需要定义整个搜索字符串。您可以通过将内部双引号加倍,将其作为
实体写入,来避免内部双引号,但也可以使用临时xml片段。类似于以下内容:

xquery version "1.0-ml";

xdmp:document-insert("/test.xml", <root>
  <pubTitle>'test'' pu'b'</pubTitle>
  <firstPage>12</firstPage>
  <lastPage>45</lastPage>
</root>)

;

xquery version "1.0-ml";

import module namespace search = "http://marklogic.com/appservices/search"
     at "/MarkLogic/appservices/search/search.xqy";

let $searchText := <txt>'test'' pu'b'</txt>/concat('"', ., '"')
return
  search:search(
    "pubTitle:" || $searchText,
    <options xmlns="http://marklogic.com/appservices/search">
      <constraint name="pubTitle">
        <value>
          <element ns="" name="pubTitle"/>
        </value>
      </constraint>
    </options>
  )
xquery版本“1.0-ml”;
xdmp:documentinsert(“/test.xml”,
'测试''pu'b'
12
45
)
;
xquery版本“1.0-ml”;
导入模块命名空间搜索=”http://marklogic.com/appservices/search"
位于“/MarkLogic/appservices/search/search.xqy”;
让$searchText:='test''pu'b'/concat('''',,''''')
返回
搜索:搜索(
pubTitle:| |$searchText,
)

我希望这能帮到你!

你的例子是“
pubTitle:“test pub”
”(你用双引号来包装你的搜索短语,但我认为应该是
pubTitle:“test pub”
。打字还是故意的?它是用双引号(“pubTitle:“test pub”)括起来的)我将其作为搜索的第一个参数传递:search,编辑问题alsoI谈论的是
test pub
周围的引号。是的,有两个双单引号…如果只有一个单引号,则没有问题搜索api将按预期形成cts查询…@grtjn如果您理解问题,请帮助。
<constraint name="pubTitle">
    <value>
       <element ns="" name="pubTitle"/>
    </value>
</constraint>
xquery version "1.0-ml";

xdmp:document-insert("/test.xml", <root>
  <pubTitle>'test'' pu'b'</pubTitle>
  <firstPage>12</firstPage>
  <lastPage>45</lastPage>
</root>)

;

xquery version "1.0-ml";

import module namespace search = "http://marklogic.com/appservices/search"
     at "/MarkLogic/appservices/search/search.xqy";

let $searchText := <txt>'test'' pu'b'</txt>/concat('"', ., '"')
return
  search:search(
    "pubTitle:" || $searchText,
    <options xmlns="http://marklogic.com/appservices/search">
      <constraint name="pubTitle">
        <value>
          <element ns="" name="pubTitle"/>
        </value>
      </constraint>
    </options>
  )