当我使用http://localhost:8003/v1/search?q=harry&format=json使用REST API进行基本搜索时,我从MarkLogic获得包含harry的所有文档的结果。
{
"snippet-format": "snippet",
"total": 2,
"start": 1,
"page-length": 10,
"results": [
{
"index": 1,
"uri": "/store/books/children/c1",
"path": "fn:doc(\"/store/books/children/c1\")",
"score": 16384,
"confidence": 0.5254987,
"fitness": 0.6964535,
"href": "/v1/documents?uri=%2Fstore%2Fbooks%2Fchildren%2Fc1",
"mimetype": "application/xml",
"format": "xml",
"matches": [
{
"path": "fn:doc(\"/store/books/children/c1\")/book/title",
"match-text": [
{
"highlight": "Harry"
},
" Potter"
]
}
]
},
{
"index": 2,
"uri": "/store/books/children/c2",
"path": "fn:doc(\"/store/books/children/c2\")",
"score": 16384,
"confidence": 0.5254987,
"fitness": 0.6964535,
"href": "/v1/documents?uri=%2Fstore%2Fbooks%2Fchildren%2Fc2",
"mimetype": "application/xml",
"format": "xml",
"matches": [
{
"path": "fn:doc(\"/store/books/children/c2\")/book/title",
"match-text": [
{
"highlight": "Harry"
},
" Potter Part 1"
]
}
]
}
],
"qtext": "harry",
"metrics": {
"query-resolution-time": "PT0.0038395S",
"snippet-resolution-time": "PT0.001753S",
"total-time": "PT0.0068583S"
}
}
但我希望响应不仅包含文档信息,还要返回文档。所以我不必单独打电话来获取文件。
答案 0 :(得分:4)
您可以将Accept
header设置为multipart/mixed
来执行此操作。如果您想要搜索响应以及匹配的文档,请设置view=results
请求参数。
有关详细信息,请参阅以下内容: http://docs.marklogic.com/guide/rest-dev/bulk#id_65903
答案 1 :(得分:0)
如果multipart/mixed
碰巧不是一个选项(也许是因为你在浏览器中使用了响应),你也可以看看使用<extract-document-data selected="all"/>
,可能与将XML转换为JSON的转换相结合为了方便处理(extractedToJson.sjs将是一个很好的例子)。
请注意,包含实际文档可能会严重降低搜索结果的传输速度,尤其是在文档很大的情况下。
HTH!