MarkLogic 变音符号不敏感片段

MarkLogic diacritic-insensitive snippet

目前,我正在使用此代码生成代码段,基于我从 MarkLogic 搜索中获得的 JSON 文档。

xquery version "1.0-ml";
module namespace searchlib="http://ihs.com/lib/searchlib";
import module namespace search="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; 
import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";

declare function searchlib:get-snippet($docc,$words) {
  let $doc:= json:transform-from-json($docc)
  let $squery := search:parse($words)
  let $result := <result>{search:snippet($doc,$squery,
  <transform-results apply="snippet" xmlns="http://marklogic.com/appservices/search">
          <max-snippet-chars>255</max-snippet-chars>

      </transform-results>)}</result>

  return $result//search:match
};

执行搜索时我正在使用:

cts.jsonPropertyValueQuery(fieldname, values, 
                                             ['case-insensitive', 'diacritic-insensitive'])

所以搜索工作时不区分变音符号并产生良好的结果,但在 search:snippet 中我无法像在 cts.jsonPropertyValueQuery.

中那样传递 diacritic-insensitive 选项

documentation中我可以在描述中看到这个

Options to define the search grammar and control the search. See description for $options for the function search:search. Note that you cannot specify the apply attribute on the transform-results option with search:snippet; to use a different snippetting function, use search:search or search:resolve instead.

但在这里是:

search:snippet(
   $result as node(),
   $cts-query as schema-element(cts:query),
   [$options as element(search:transform-results)?]
) as element(search:snippet)

那么这是否意味着我无法将其他选项传递给 search:snippet?或者是否有这样做的选项?

我正在使用 chávez 对其进行测试,它正在产生结果,但只有包含完全匹配的文档才能正确生成片段,这意味着文档

Chavez did something

不会在 Chavez

上突出显示

Chávez did something

会得到一个亮点

提前致谢!

问题在于没有将选项传递给 search:snippet,而是传递给 search:parse

xquery version "1.0-ml";
module namespace searchlib="http://ihs.com/lib/searchlib";
import module namespace search="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; 
import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";

declare function searchlib:get-snippet($docc,$words) {
  let $doc:= json:transform-from-json($docc)
  let $squery := search:parse($words,
<options xmlns="http://marklogic.com/appservices/search">
<term>
<term-option>case-insensitive</term-option>
<term-option>diacritic-insensitive</term-option>
</term>
</options>, "cts:query")

  let $result := <result>{search:snippet($doc,$squery,
  <transform-results apply="snippet" xmlns="http://marklogic.com/appservices/search">
          <max-snippet-chars>255</max-snippet-chars>

      </transform-results>)}</result>

  return $result//search:match
};

及格

<term-option>diacritic-insensitive</term-option>

search:parse 成功了。

MarkLogic 的解释如下:

The search:snippet() function allows you to extract matching text and returns the matches wrapped in a containing node, with highlights tagged. However, to allow the search:snippet to extract the correct text, the cts:query() that is passed to the snippet should match the sequence of values. For search:snippet, cts:query is typically a result of a call to search:parse. The search:parse() function parses query text according to given options and returns the appropriate cts:query XML.