add options to addFacet for size and silent
This commit is contained in:
@@ -543,7 +543,7 @@ my.Query = Backbone.Model.extend({
|
|||||||
// Add a Facet to this query
|
// Add a Facet to this query
|
||||||
//
|
//
|
||||||
// See <http://www.elasticsearch.org/guide/reference/api/search/facets/>
|
// See <http://www.elasticsearch.org/guide/reference/api/search/facets/>
|
||||||
addFacet: function(fieldId) {
|
addFacet: function(fieldId, size, silent) {
|
||||||
var facets = this.get('facets');
|
var facets = this.get('facets');
|
||||||
// Assume id and fieldId should be the same (TODO: this need not be true if we want to add two different type of facets on same field)
|
// Assume id and fieldId should be the same (TODO: this need not be true if we want to add two different type of facets on same field)
|
||||||
if (_.contains(_.keys(facets), fieldId)) {
|
if (_.contains(_.keys(facets), fieldId)) {
|
||||||
@@ -552,8 +552,13 @@ my.Query = Backbone.Model.extend({
|
|||||||
facets[fieldId] = {
|
facets[fieldId] = {
|
||||||
terms: { field: fieldId }
|
terms: { field: fieldId }
|
||||||
};
|
};
|
||||||
|
if (!_.isUndefined(size)) {
|
||||||
|
facets[fieldId].terms.size = size;
|
||||||
|
}
|
||||||
this.set({facets: facets}, {silent: true});
|
this.set({facets: facets}, {silent: true});
|
||||||
|
if (!silent) {
|
||||||
this.trigger('facet:add', this);
|
this.trigger('facet:add', this);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addHistogramFacet: function(fieldId) {
|
addHistogramFacet: function(fieldId) {
|
||||||
var facets = this.get('facets');
|
var facets = this.get('facets');
|
||||||
|
|||||||
@@ -347,6 +347,12 @@ test('Query', function () {
|
|||||||
deepEqual({terms: {field: 'xyz'}}, query.get('facets')['xyz']);
|
deepEqual({terms: {field: 'xyz'}}, query.get('facets')['xyz']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Query.addFacet', function () {
|
||||||
|
var query = new recline.Model.Query();
|
||||||
|
query.addFacet('xyz', 25);
|
||||||
|
deepEqual({terms: {field: 'xyz', "size": 25}}, query.get('facets')['xyz']);
|
||||||
|
});
|
||||||
|
|
||||||
test('Query.addFilter', function () {
|
test('Query.addFilter', function () {
|
||||||
var query = new recline.Model.Query();
|
var query = new recline.Model.Query();
|
||||||
query.addFilter({type: 'term', field: 'xyz'});
|
query.addFilter({type: 'term', field: 'xyz'});
|
||||||
|
|||||||
Reference in New Issue
Block a user