“Managing buckets”
The buckets (or aggregated results) of a search can be organised using the JS API.
Subscription
The first step, before being able to manipulate these buckets, is to subscribe to buckets retrieval from FlowerDocs Core:
or by search, providing
searchIdthe identifier of the search in question:var bucketAPI = JSAPI.get().getHelperFactory().getBucketAPI(); bucketAPI.register(searchId, function(buckets, callback){ callback.onProcessed(buckets); });or for all searches:
var bucketAPI = JSAPI.get().getHelperFactory().getBucketAPI(); bucketAPI.register(, function(buckets, callback){ callback.onProcessed(buckets); });
The registered subscription is called up with two variables:
- The
bucketsarray contains all buckets of the same level - The
callbackprovided as input to the subscription must be called with a bucket array
Bucket modification
The JS API lets you modify buckets resolved by FlowerDocs Core by exhibiting the following methods:
| Function | Description |
|---|---|
| getName() | Returns the name |
| setName(name) | Modifies the name |
| getCount() | Returns the number of components contained in the bucket (sum of child buckets) |
| setCount(long count) | Modifies the number of components contained in the bucket |
| getLevel() | Returns bucket level |
| hasChildren() | Determines whether the bucket contains child buckets |
| getChildren() | Retrieves child buckets |
| hasParent() | Determines whether the bucket has a bucket parent |
| getParents() | Retrieves parent buckets (all parent levels) |
| getRequest() | Retrieves the request executed to determine the bucket’s contents |
| setRequest(SearchRequest request) | Modifies the request executed to determine the bucket’s contents |
Hiding a bucket
The setSkipDisplay(boolean skip) function is also exhibited on the Bucket object, enabling a bucket to be hidden and only its children displayed.
Recovery of buckets after resolution
The buckets of a search can be recovered after resolution as follows:
var bucketAPI = JSAPI.get().getHelperFactory().getBucketAPI();
bucketAPI.registerForResolved("searchId", function(buckets){
for(i in buckets){
var bucket = buckets[i];
console.info(bucket.getName()+ " has been resolved, count=" +bucket.getCount());
}
callback.onProcessed(buckets);
});
This allows you to obtain resolved buckets, including counters in the case of partial buckets.