【问题标题】:Search response from Marklogic with all matching documents使用所有匹配文档从 Marklogic 搜索响应
【发布时间】:2017-04-27 10:41:40
【问题描述】:

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

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

【问题讨论】:

    标签: marklogic marklogic-8


    【解决方案1】:

    您可以通过将Accept header 设置为multipart/mixed 来做到这一点。如果您想要搜索响应以及匹配的文档,请设置 view=results 请求参数。

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

    【讨论】:

      【解决方案2】:

      如果multipart/mixed 碰巧不是一个选项(可能是因为您在浏览器中使用响应),您还可以考虑使用<extract-document-data selected="all"/>,可能结合将XML 转换为JSON 的转换以方便处理( extractedToJson.sjs 就是一个很好的例子)。

      请注意,包含实际文档可能会严重减慢搜索结果的传输速度,尤其是在文档很大的情况下。

      HTH!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多