From fbc322d963feac6d2c403980c33361467e5a6f71 Mon Sep 17 00:00:00 2001 From: Marc Portier Date: Sun, 20 Jul 2014 14:04:20 +0200 Subject: [PATCH] Alternative implementation for the #83 suggestion. Making it not-conflicting with the #88 implementation by renaming get --> handleGet() Adding the handlePost to complete the use-case behind this Not returning self but rather the request since that seems the standard pattern in v0.3.x --- lib/solr.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/solr.js b/lib/solr.js index 8b58f15f..6398a52d 100644 --- a/lib/solr.js +++ b/lib/solr.js @@ -539,7 +539,7 @@ Client.prototype.spell = function(query,callback){ /** * Make an arbitraty get request to Solr * - * @param {Path|String} Path + * @param {Path|String} handlerPath * @param {Query|String} query * @param {Function} callback(err,obj) - a function executed when the Solr server responds or an error occurs * @param {Error} callback().err @@ -549,18 +549,45 @@ Client.prototype.spell = function(query,callback){ * @api public */ -Client.prototype.get = function(path,query,callback){ +Client.prototype.handleGet = function(handlerPath,query,callback){ var self = this; - // Allow to be more flexible allow query to be a string and not only a Query object var parameters = query.build ? query.build() : query; - this.options.fullPath = [this.options.path,this.options.core,path + '?' + parameters + '&wt=json'] + this.options.fullPath = [this.options.path,this.options.core,handlerPath + '?' + parameters + '&wt=json'] .filter(function(element){ if(element) return true; return false; }) .join('/'); ; - queryRequest(this.options,callback); - return self; + return queryRequest(this.options,callback); +} + +/** + * Make an arbitraty post request to Solr + * + * @param {Path|String} handlerPath + * @param {Query|String} query + * @param {Function} callback(err,obj) - a function executed when the Solr server responds or an error occurs + * @param {Error} callback().err + * @param {Object} callback().obj - JSON response sent by the Solr server deserialized + * + * @return {Client} + * @api public + */ + +Client.prototype.handlePost = function(handlerPath,data,options,callback){ + var self = this; + if(typeof(options) === 'function'){ + callback = options; + options = {}; + } + this.options.json = JSON.stringify(data); + this.options.fullPath = [this.options.path,this.options.core,handlerPath + '?' + parameters + '&wt=json'] + .filter(function(element){ + if(element) return true; + return false; + }) + .join('/'); ; + return updateRequest(this.options,callback); } /**