Skip to content

Commit

Permalink
Alternative implementation for the lbdremy#83 suggestion.
Browse files Browse the repository at this point in the history
Making it not-conflicting with the lbdremy#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
  • Loading branch information
marc-portier committed Jul 20, 2014
1 parent 312da1d commit fbc322d
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions lib/solr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit fbc322d

Please sign in to comment.