MarkLogic 10 Product Documentation
ValuesSearch.groupInto

ValuesSearch.groupInto(
   bounds as bucketDefinition
) as ValuesSearch

Summary

Groups the values into buckets between bound values, which must appear in increasing order.

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

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.

You cannot use this method with ValuesSearch.match or ValuesSearch.aggregate.

See Also

Example


const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.values('price')
  .where(cts.directoryQuery('/books/'))
  .groupInto([10,20])
  .result();

/* Result: A set of 3 unnamed buckets, similar to the following:
[{"minimum":8, "maximum":9, "upperBound":10}, 
  {"minimum":10, "maximum":18, "lowerBound":10, "upperBound":20}, 
  {"minimum":20, "maximum":30, "lowerBound":20}]
*/
   

Example


const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.values('price')
  .where(cts.directoryQuery('/books/'))
  .groupInto([
    jsearch.bucketName(), 10,
    jsearch.bucketName(), 20,
    jsearch.bucketName()
    ])
  .reduce({frequency: 'item'})
  .result();

/* Result: Three buckets with the default name. The bucket name is returned 
    in a "name" property. If you request frequency data, an object is returned
    instead of an array, and the object has a property corresponding to
    each bucket name. See the next example for this style of output.
    
[ { "minimum": 8,
    "maximum": 9,
    "upperBound": 10,
    "name": "under $10"
  },
  { "minimum": 10,
    "maximum": 18,
    "lowerBound": 10,
    "upperBound": 20,
    "name": "$10 to $19.99"
  },
  { "minimum": 20,
    "maximum": 30,
    "lowerBound": 20,
    "upperBound": 1000,
    "name": "over $20"
  }
]
*/
   

Example


const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.values('price')
  .where(cts.directoryQuery('/books/'))
  .groupInto([
    jsearch.bucketName('under $10'), 10,
    jsearch.bucketName('$10 to $19.99'), 20,
    jsearch.bucketName('over $20'), 1000
    ])
  .reduce({frequency: 'item'})
  .result();

/* Result: A set of three buckets with custom names, similar to the following.
    The result is an object rather than an array because of the inclusion
    of frequency data.

{ "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,
      "upperBound": 1000
    },
    "frequency": 3
  }
}
*/
   
Powered by MarkLogic Server | Terms of Use | Privacy Policy