Loading TOC...

DocumentsSearch.result

DocumentsSearch.result(
   $type as string
) as object

Summary

Executes the document search definition and returns a result object with an estimate property for the total number of matched documents, a results property with an array holding the subsequence of documents in the slice, and other properties if specified by withOptions().

Parameters
$type Optional. Specify whether to return the documents as a value (default) or a streaming iterator. When you return the documents as a value, the documents are an array in the returned results object, unless your query uses DocumentsSearch.reduce. Allowed values: 'value', 'iterator'.

See Also

Example


var jsearch = require('/MarkLogic/jsearch.sjs');
var results = jsearch.documents()
  .where(cts.wordQuery('california'))
  .slice(0,2)
  .result()
results

==> Search metadata and document contents for the first 2 documents
    containing the word "california".

{ "results": [
    { "index": 0,
      "uri": "/books/steinbeck1.json",
      "score": 18432,
      "confidence": 0.4903561770916,
      "fitness": 0.71398365497589,
      "document": {
        "title": "The Grapes of Wrath",
        "author": "John Steinbeck",
        "edition": {
          "format": "paperback",
          "price": 10
        },
        "synopsis": "Chronicles the 1930s Dust Bowl migration of one 
           Oklahoma farm family, from their homestead and forced to the 
           promised land of California."
      }
    },
    { "index": 1,
      "uri": "/books/steinbeck2.json",
      "score": 18432,
      "confidence": 0.4903561770916,
      "fitness": 0.71398365497589,
      "document": {
        "title": "Of Mice and Men",
        "author": "John Steinbeck",
        "edition": {
          "format": "hardback",
          "price": 20
        },
        "synopsis": "A tale of an unlikely pair of drifters who move from 
          job to job as farm laborers in California, until it all goes 
          horribly awry."
      }
    }
  ],
  "estimate": 3
}
   

Example


var jsearch = require('/MarkLogic/jsearch.sjs');
var results = jsearch.documents()
  .where(cts.wordQuery('california'))
  .slice(0,2)
  .result('iterator')
results

==> Search metadata and document contents for the first 2 documents
    containing the word "california". The value of the "results"
    property is a streaming iterator over each result. 

{"results": anIterator, 
 "estimate":3}
   

Example


var jsearch = require('/MarkLogic/jsearch.sjs');
var results = jsearch.documents()
  .where(cts.wordQuery('california'))
  .orderBy(cts.indexOrder(cts.jsonPropertyReference('price', ['type=float'])))
  .slice(0,5)
  .map({snippet: true})
  .result()

==> Search metadata and snippets from the first 5 documents containing 
    the word "california", ordered by the values in the price JSON property.

{ "results": [
    { "score": 18432,
      "fitness": 0.72760027647018,
      "uri": "/books/steinbeck1.json",
      "path": "fn:doc(\"/books/steinbeck1.json\")",
      "confidence": 0.41591840982437,
      "index": 0,
      "matches": [ {
          "path": "fn:doc(\"/books/steinbeck1.json\")/text(\"synopsis\")",
          "matchText": [
            "...of one Oklahoma farm family, from their homestead and 
             forced to the promised land of ",
            { "highlight": "California" },
            "."
          ]
      } ]
    },
    { "score": 18432,
      "fitness": 0.72760027647018,
      "uri": "/books/steinbeck3.json",
      "path": "fn:doc(\"/books/steinbeck3.json\")",
      "confidence": 0.41591840982437,
      "index": 1,
      "matches": [ {
          "path": "fn:doc(\"/books/steinbeck3.json\")/text(\"synopsis\")",
          "matchText": [
            "Follows the intertwined destinies of two ",
            { "highlight": "California" },
            " families whose generations reenact the fall of Adam and 
             Eve and the rivalry of Cain..."
          ]
      } ]
    },
    { "score": 18432,
      "fitness": 0.72760027647018,
      "uri": "/books/steinbeck2.json",
      "path": "fn:doc(\"/books/steinbeck2.json\")",
      "confidence": 0.41591840982437,
      "index": 2,
      "matches": [ {
          "path": "fn:doc(\"/books/steinbeck2.json\")/text(\"synopsis\")",
          "matchText": [
            "...an unlikely pair of drifters who move from job to job 
             as farm laborers in ",
            { "highlight": "California" },
            ", until it all goes horribly awry."
          ]
      } ]
    }
  ],
  "estimate": 3
}
   

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy