Search code examples
marklogicmarklogic-8

Search response from Marklogic with all matching documents


When I do basic search using the REST API using http://localhost:8003/v1/search?q=harry&format=json, I get a result from MarkLogic with all documents containing 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"
  }
}

But I want the response to not just contain the information of document but to return the document as well. So that I don't have to do separate calls to get the documents.


Solution

  • You can do this by setting the Accept header to multipart/mixed. If you want the search response as well as the matching documents, set the view=results request parameter.

    See the following for more details: http://docs.marklogic.com/guide/rest-dev/bulk#id_65903