使用所有匹配文档搜索 Marklogic 的响应

Search response from Marklogic with all matching documents

当我使用 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"
  }
}

但我希望响应不仅包含文档的信息,还包含 return 文档的信息。这样我就不必单独调用来获取文档了。

您可以通过设置 Accept header to multipart/mixed. If you want the search response as well as the matching documents, set the view=results 请求参数来完成此操作。

有关详细信息,请参阅以下内容: http://docs.marklogic.com/guide/rest-dev/bulk#id_65903

如果 multipart/mixed 恰好不是一个选项(可能是因为您在浏览器中使用响应),您还可以考虑使用 <extract-document-data selected="all"/>, potentially combined with a transform that converts XML to JSON for processing convenience (extractedToJson.sjs 将是一个很好的例子)。

请注意,包括实际文档会严重降低搜索结果的传输速度,尤其是在文档很大的情况下。

HTH!