FacetDefinition.orderBy( sortKey as string, direction as string ) as FacetDefinition
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. |
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.
// 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] // ] // }}
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.