diff --git a/lib/query.js b/lib/query.js index 8fb1c2f4..90f0160c 100644 --- a/lib/query.js +++ b/lib/query.js @@ -239,6 +239,26 @@ Query.prototype.matchFilter = function(field,value){ return self; } +/** + * Filter the set of documents found before to return the result with the given expression. + * + * @param {String} expression - expression + * + * @return {Query} + * @api public + * + * @example + * var query = client.createQuery(); + * query.q({ '*' : '*' }).matchFilter('id', 100) + */ + +Query.prototype.expressionFilter = function(expression){ + var self = this; + var parameter = 'fq=' + encodeURIComponent(expression); + this.parameters.push(parameter); + return self; +} + /** * Specify a set of fields to return. * @@ -693,6 +713,38 @@ Query.prototype.boost = function(functions){ return self; } +/** + * Create a geo-spatial query. + * + * @param {Object} options - set of options to create a spatial + * @param {Boolean} [options.on=true] - Turn on or off spatial + * @param {String} [options.pt] - The geo position point. + * @param {String} [options.sfield] - The name of the field where the confition is applied. + * @param {Number} [options.d] - The distance in kilometers. + * + * @return {Query} + * @api public + */ + +Query.prototype.spatial = function(options) { + var self = this; + if(options.on === false){ + this.parameters.push('spatial=false'); + }else{ + this.parameters.push('spatial=true'); + } + if(options.pt !== undefined) { + this.parameters.push('pt=' + encodeURIComponent(options.pt)) + } + if(options.sfield !== undefined){ + this.parameters.push('sfield=' + options.sfield) + } + if(options.d !== undefined){ + this.parameters.push('d=' + options.d) + } + return self; +} + /** * Build a querystring with the array of `this.parameters`. *