
DocumentsSearch.result( type as string ) as Iterable
Executes the document search definition and returns a result Iterable 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().
const jsearch = require('/MarkLogic/jsearch.sjs');
const results = jsearch.documents()
.where(cts.wordQuery('california'))
.slice(0,2)
.result()
results
/* Result: 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
}
*/
const jsearch = require('/MarkLogic/jsearch.sjs');
const results = jsearch.documents()
.where(cts.wordQuery('california'))
.slice(0,2)
.result('iterator')
results
/* Result: 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}
*/
const jsearch = require('/MarkLogic/jsearch.sjs');
const results = jsearch.documents()
.where(cts.wordQuery('california'))
.orderBy(cts.indexOrder(cts.jsonPropertyReference('price', ['type=float'])))
.slice(0,5)
.map({snippet: true})
.result()
/* 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
}
*/
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.