Loading TOC...

MarkLogic Server 11.0 Product Documentation
jsearch.facets

jsearch.facets(
   facets as FacetDefinition,
   document as DocumentsSearch
) as FacetsSearch

Summary

Creates a FacetsSearch object to define and execute a report listing value facets and, optionally, a page of documents.

Parameters
facets One or an array of objects specifying the facets listed in the report.
document An optional object specifying a page of documents to retrieve as part of the report.

Usage Notes

Define the facets using FacetDefinition.

Use the methods of FacetsSearch to further refine your facets, such as defining a set of documents to return along with the facets.

See Also

Example


// Generate facets on the "author" and "format" JSON properties of
// documents where the "price" property value is less than 15.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.facets([
    jsearch.facet('Author', 'author'),
    jsearch.facet('MediaFormat', 'format')])
  .where(jsearch.byExample({price: {$lt: 15}}))
  .result()

/* Result: A facets summary similar to the following:

{"facets":{
  "Author": {
    "Mark Twain": 2, 
    "John Steinbeck": 1
  }, 
  "MediaFormat": {
    "paperback": 3
}}}
*/
   

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.