Loading TOC...

MarkLogic 10 Product Documentation
jsearch.bucketName

jsearch.bucketName(
   name as xs.string
) as BucketNameDefinition

Summary

Names a bucket below the smallest bound, between two bounds, or above the largest bound as input for the ValuesSearch.groupInto or FacetDefinition.groupInto method.

Parameters
name The name for the bucket. Omit to use the default name for the bucket.

Usage Notes

If at least one bucket for grouped values is named, buckets without an explicit name will be assigned a default name.

See Also

Example


// Explicitly specify bucket names for a facets query
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'), 1000
    ]))
  .where(cts.directoryQuery('/books/'))
  .result();

/* Results:

{"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,
        "upperBound": 1000
      },
      "frequency": 2
    }
  }
} }
*/
   

Example


// Generate bucket names from the value ranges for a values query
jsearch.values('price')
  .where(cts.directoryQuery('/books/'))
  .groupInto([
    jsearch.bucketName(), 10,
    jsearch.bucketName(), 20,
    jsearch.bucketName()
    ])
  .result();

/* Result: The "name" property of each facet bucket, generated from the bucket
    boundaries.

[ {
    "minimum": 8,
    "maximum": 9,
    "upperBound": 10,
    "name": "x < 10"
  }, {
    "minimum": 10,
    "maximum": 19,
    "lowerBound": 10,
    "upperBound": 20,
    "name": "10 <= x < 20"
  }, {
    "minimum": 20,
    "maximum": 30,
    "lowerBound": 20,
    "name": "20 <= x"
} ]
*/
   

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.