现在,我正在使用此代码生成代码段,基于我从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'])
因此搜索工作变量不敏感并产生良好的结果,但在搜索:片段我无法传递变音不敏感选项,如cts.jsonPropertyValueQuery.
在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)
那么这是否意味着我无法通过其他选项进行搜索:片段?或者可以选择这样做吗?
我正在使用chávez测试它并且它正在产生结果,但是仅对包含完全匹配的文档正确生成片段,这意味着该文档
Chavez did something
对查韦斯不会高兴
Chávez did something
会得到一个高光
提前致谢!
最佳答案 问题在于没有传递搜索选项:片段,而是搜索:解析
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>
搜索:解析使它工作.
以下是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, thects:query()
that is passed to the snippet should match the
sequence of values. Forsearch:snippet
,cts:query
is typically a
result of a call tosearch:parse
. Thesearch:parse()
function parses
query text according to given options and returns the appropriate
cts:query
XML.