FacetDefinition.groupInto( bounds as bucketDefinition ) as FacetDefinition
Groups facet values into buckets between bound values
as in a ValuesSearch
definition.
You can create buckets using the jsearch.makeBucket
or jsearch.makeHeatMap
helper functions.
Each bucket includes the previous boundary and excludes the
following boundary. To assign names to the buckets, alternate
calls to jsearch.bucketName
with the bound values.
Empty buckets are thrown away by default, so it can be
efficient to estimate bounds instead of determining precisely
the smallest and largest bound. You can use
jsearch.makeHeatMap
to group geospatial values
into a heatmap.
// Group facet values into buckets using the generated default bucket names. const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.facets( jsearch.facet('price') .groupInto([ jsearch.bucketName(), 10, jsearch.bucketName(), 20, jsearch.bucketName()]) ).result() /* The result is similar to the following: {"facets": { "price": { "x < 10": { "value": { "minimum": 8, "maximum": 9, "upperBound": 10 }, "frequency": 2 }, "10 <= x < 20": { "value": { "minimum": 10, "maximum": 18, "lowerBound": 10, "upperBound": 20 }, "frequency": 4 }, "20 <= x": { "value": { "minimum": 20, "maximum": 30, "lowerBound": 20 }, "frequency": 2 } } } } */
// Group facet values into buckets with custom names. const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.facets( jsearch.facet('Price','price') .groupInto([ jsearch.bucketName('under $10'), 10, jsearch.bucketName('$10 to $19.99'), 20, jsearch.bucketName('over $20') ])) .where(cts.directoryQuery('/books/')) .result(); /* The result is similar to the following: {"facets": { "Price": { "under $10": { "value": { "minimum": 8, "maximum": 9, "upperBound": 10 }, "frequency": 2 }, "$10 to $19.99": { "value": { "minimum": 10, "maximum": 18, "lowerBound": 10, "upperBound": 20 }, "frequency": 4 }, "over $20": { "value": { "minimum": 20, "maximum": 30, "lowerBound": 20 }, "frequency": 2 } } } } */