MarkLogic Server 11.0 Product Documentation
FacetDefinition.groupInto

FacetDefinition.groupInto(
   bounds as bucketDefinition
) as FacetDefinition

Summary

Groups facet values into buckets between bound values as in a ValuesSearch definition.

Parameters
bounds Defines the boundary values separating the buckets. A bucket definition can be an array of boundary values or an array of (bucketNames, boundaryValue) pairs. For geospatial buckets, a boundary value can be an object with lat and lon properties. Helper functions are available for creating bucket definitions; for details, see the Usage Notes.

Usage Notes

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.

See Also

Example


// 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
    }
  }
} }
*/
   

Example


// 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
    }
  }
} }
*/
   
Powered by MarkLogic Server | Terms of Use | Privacy Policy