Loading TOC...


   $sortKey as string,
   $direction as string
) as FacetDefinition


Specifies the sort order for facet values, as in a ValuesSearch definition.

$sortKey Specifies whether to sort on the "item" or "frequency".
$direction Specifies whether to sort in "ascending" or "descending" order.

Usage Notes

When you add an orderBy clause to a facet definition, the default output from jsearch.facets for that facet becomes an array of arrays instead of a JSON object. Each array item is of the form [itemValue, frequency] and the array items are ordered according to the orderBy configuration.

See Also


// Generate facets on the "author" property and order them by frequency.
const jsearch = require('/MarkLogic/jsearch.sjs');
    jsearch.facet('Author', 'author').orderBy('frequency')])
  .where(jsearch.byExample({price: {$lt: 50}}))

// Produces results of the following form:
// {"facets":{
//   "Author":[
//     ["Mark Twain", 4], 
//     ["John Steinbeck", 3], 
//     ["Robert Frost", 1]
//   ]
// }}

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