UNPKG

elastic.js

Version:

Javascript API for ElasticSearch DSL

106 lines (85 loc) 3.24 kB
/** @class <p>A constant score query wraps another <code>Query</code> or <code>Filter</code> and returns a constant score for each result that is equal to the query boost.</p> <p>Note that lucene's query normalization (queryNorm) attempts to make scores between different queries comparable. It does not change the relevance of your query, but it might confuse you when you look at the score of your documents and they are not equal to the query boost value as expected. The scores were normalized by queryNorm, but maintain the same relevance.</p> @name ejs.ConstantScoreQuery @ejs query @borrows ejs.QueryMixin.boost as boost @borrows ejs.QueryMixin._type as _type @borrows ejs.QueryMixin.toJSON as toJSON @desc <p>Constructs a query where each documents returned by the internal query or filter have a constant score equal to the boost factor.</p> */ ejs.ConstantScoreQuery = function () { var _common = ejs.QueryMixin('constant_score'), query = _common.toJSON(); return extend(_common, { /** Adds the query to apply a constant score to. @member ejs.ConstantScoreQuery @param {Object} oQuery A valid <code>Query</code> object @returns {Object} returns <code>this</code> so that calls can be chained. */ query: function (oQuery) { if (oQuery == null) { return query.constant_score.query; } if (!isQuery(oQuery)) { throw new TypeError('Argument must be a Query'); } query.constant_score.query = oQuery.toJSON(); return this; }, /** Adds the filter to apply a constant score to. @member ejs.ConstantScoreQuery @param {Object} oFilter A valid <code>Filter</code> object @returns {Object} returns <code>this</code> so that calls can be chained. */ filter: function (oFilter) { if (oFilter == null) { return query.constant_score.filter; } if (!isFilter(oFilter)) { throw new TypeError('Argument must be a Filter'); } query.constant_score.filter = oFilter.toJSON(); return this; }, /** Enables caching of the filter. @member ejs.ConstantScoreQuery @param {Boolean} trueFalse A boolean value. @returns {Object} returns <code>this</code> so that calls can be chained. */ cache: function (trueFalse) { if (trueFalse == null) { return query.constant_score._cache; } query.constant_score._cache = trueFalse; return this; }, /** Set the cache key. @member ejs.ConstantScoreQuery @param {String} k A string cache key. @returns {Object} returns <code>this</code> so that calls can be chained. */ cacheKey: function (k) { if (k == null) { return query.constant_score._cache_key; } query.constant_score._cache_key = k; return this; } }); };