elastic.js
Version:
Javascript API for ElasticSearch DSL
145 lines (116 loc) • 4.17 kB
JavaScript
/**
@mixin
<p>The FacetMixin provides support for common options used across
various <code>Facet</code> implementations. This object should not be
used directly.</p>
@name ejs.FacetMixin
*/
ejs.FacetMixin = function (name) {
var facet = {};
facet[name] = {};
return {
/**
<p>Allows you to reduce the documents used for computing facet results.</p>
@member ejs.FacetMixin
@param {Object} oFilter A valid <code>Filter</code> object.
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
facetFilter: function (oFilter) {
if (oFilter == null) {
return facet[name].facet_filter;
}
if (!isFilter(oFilter)) {
throw new TypeError('Argument must be a Filter');
}
facet[name].facet_filter = oFilter.toJSON();
return this;
},
/**
<p>Computes values across the entire index</p>
@member ejs.FacetMixin
@param {Boolean} trueFalse Calculate facet counts globally or not.
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
global: function (trueFalse) {
if (trueFalse == null) {
return facet[name].global;
}
facet[name].global = trueFalse;
return this;
},
/**
<p>Sets the mode the facet will use.<p>
<dl>
<dd><code>collector</code></dd>
<dd><code>post</code></dd>
<dl>
@member ejs.FacetMixin
@param {String} m The mode: collector or post.
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
mode: function (m) {
if (m == null) {
return facet[name].mode;
}
m = m.toLowerCase();
if (m === 'collector' || m === 'post') {
facet[name].mode = m;
}
return this;
},
/**
<p>Enables caching of the <code>facetFilter</code></p>
@member ejs.FacetMixin
@param {Boolean} trueFalse If the facetFilter should be cached or not
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
cacheFilter: function (trueFalse) {
if (trueFalse == null) {
return facet[name].cache_filter;
}
facet[name].cache_filter = trueFalse;
return this;
},
/**
<p>Computes values across the the specified scope</p>
@deprecated since elasticsearch 0.90
@member ejs.FacetMixin
@param {String} scope The scope name to calculate facet counts with.
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
scope: function (scope) {
return this;
},
/**
<p>Sets the path to the nested document if faceting against a
nested field.</p>
@member ejs.FacetMixin
@param {String} path The nested path
@returns {Object} returns <code>this</code> so that calls can be chained.
*/
nested: function (path) {
if (path == null) {
return facet[name].nested;
}
facet[name].nested = path;
return this;
},
/**
The type of ejs object. For internal use only.
@member ejs.FacetMixin
@returns {String} the type of object
*/
_type: function () {
return 'facet';
},
/**
<p>Retrieves the internal <code>facet</code> object. This is typically used by
internal API functions so use with caution.</p>
@member ejs.FacetMixin
@returns {String} returns this object's internal <code>facet</code> property.
*/
toJSON: function () {
return facet;
}
};
};