我正在使用 Roxy 来管理我的项目。也使用 MarkLogic 8.0-6.1
我正在尝试提交一个 searchTerm,并返回一个自定义格式search:snippet
以下是我正在采取的完整步骤:
./../roxy/ml new test-app --server-version=8 --app-type=rest
配置我的 build.properties
cd test-app/
./ml local bootstrap
现在我有了我的项目结构。
创建文件 - test-app/rest-api/ext/show-search.xqy
xquery version "1.0-ml";
module namespace ss = "http://marklogic.com/rest-api/resource/show-search";
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 ss:get(
$context as map:map,
$params as map:map
) as document-node()*
{
map:put($context, "output-types", "application/json"),
map:put($context, "output-status", (200, "OK")),
let $search-term := map:get($params, "searchTerm")
let $query := search:search($search-term,
<options xmlns="http://marklogic.com/appservices/search">
<transform-results apply="raw"/>
</options>
)
return document {$query}
};
(:
:)
declare
function ss:put(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()?
{
map:put($context, "output-types", "application/xml"),
map:put($context, "output-status", (201, "Created")),
document { "PUT called on the ext service extension" }
};
(:
:)
declare
function ss:post(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()*
{
map:put($context, "output-types", "application/xml"),
map:put($context, "output-status", (201, "Created")),
document { "POST called on the ext service extension" }
};
(:
:)
declare
function ss:delete(
$context as map:map,
$params as map:map
) as document-node()?
{
map:put($context, "output-types", "application/xml"),
map:put($context, "output-status", (200, "OK")),
document { "DELETE called on the ext service extension" }
};
上面的 GET 请求transform-results apply=raw
正确使用了选项、部署和功能(我有一些测试文档)。
但是我不想返回整个文档,我想返回匹配的整个 json 部分,无论匹配发生在那个部分的哪个位置(较低级别)
所以我尝试自己写snipper
创建文件 - test-app/rest-api/ext/show-search-snipper.xqy
xquery version "1.0-ml";
module namespace sss = "http://marklogic.com/rest-api/resource/show-search-snipper";
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 sss:my-snippet(
$result as node(),
$ctsquery as schema-element(cts:query),
$options as element(search:transform-results)?
) as element(search:snippet)
{
<search:snippet>
</search:snippet>
};
然后我将调用更新search:search
为以下内容
let $query := search:search($search-term,
<options xmlns="http://marklogic.com/appservices/search">
<transform-results apply="my-snippet" ns="http://marklogic.com/rest-api/resource/show-search-snipper" at="show-search-snipper.xqy"/>
</options>
)
现在我应该拥有我需要的一切(我认为)
我运行部署./ml local deploy rest
并得到以下
Minty-linux test-app # ./ml local deploy rest 在 /opt/this-is-a-test/test-app/rest-api/config/properties.xml 中加载 REST 属性 在 /opt/this- 中加载 REST 选项is-a-test/test-app/rest-api/config/options
从 /opt/this-is-a-test/test-app/rest-api/ext 加载 REST 扩展
错误:400“错误请求”错误:{“errorResponse”:{“statusCode”:400,“status”:“错误请求”,“messageCode”:“RESTAPI-INVALIDCONTENT”,“消息”:“RESTAPI-INVALIDCONTENT:( err:FOER0000) 无效内容:无效的 show-search-snipper 扩展:show-search-snipper 不是有效模块,或者在 http://marklogic.com中不提供扩展功能(删除、获取、放置、发布) /rest-api/resource/show-search-snipper 命名空间"}}
所以我尝试将show-search-snipper.xqy
文件上移 1 级(到 test-app/rest-api/show-search-snipper.xqy`
运行部署 Deployment Works 没有错误 点击 URL 并收到以下信息
500 内部服务器错误 INTERNAL ERROR RESTAPI-INVALIDREQ: (err:FOER0000) 无效请求:原因:扩展显示搜索不存在。. 有关详细信息,请参阅 MarkLogic 服务器错误日志。
虽然我知道扩展程序是正确创建的,但在引入自定义 snip 功能之前它运行良好。(应用=“原始”)
有什么想法可以应用我的自定义剪辑功能或我在部署中做错了什么?