From c3064cfa4af19b2a9f060a989eeba52c0e102724 Mon Sep 17 00:00:00 2001 From: pipll Date: Mon, 15 Jun 2015 11:13:34 +0300 Subject: [PATCH 1/2] Added an ability to search using geo-spatial queries --- lib/query.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/query.js b/lib/query.js index 8fb1c2f4..f5a41d7e 100644 --- a/lib/query.js +++ b/lib/query.js @@ -693,6 +693,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`. * From c7b60a39f31b77a6413b698704b0f70f9b525c9c Mon Sep 17 00:00:00 2001 From: pipll Date: Mon, 15 Jun 2015 11:30:06 +0300 Subject: [PATCH 2/2] Added an ability to filter documents by expression --- lib/query.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/query.js b/lib/query.js index f5a41d7e..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. *