Loading TOC...

FacetDefinition.orderBy

FacetDefinition.orderBy(
   $sortKey as string,
   $direction as string
) as FacetDefinition

Summary

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

Parameters
$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

Example


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

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

Comments

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