Skip to content

Commit

Permalink
FIX: Dry Client#spell, Client#search, Client#ping, Client#realTimeGet.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbdremy committed Jul 29, 2014
1 parent 3097b9b commit 1e85a1a
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions lib/solr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*!
* solr client
* Copyright(c) 2011-2012 HipSnip Limited
* Copyright(c) 2013-2014 Rémy Loubradou
* Author Rémy Loubradou <remyloubradou@gmail.com>
* MIT Licensed
*/
Expand Down Expand Up @@ -76,6 +77,7 @@ function Client(options){
this.SELECT_HANDLER = 'select';
this.ADMIN_PING_HANDLER = 'admin/ping';
this.GET_HANDLER = 'get';
this.SPELL_HANDLER = 'spell';
}

/**
Expand Down Expand Up @@ -151,15 +153,10 @@ Client.prototype.realTimeGet = function(ids, options, callback){
options = {};
}
ids = Array.isArray(ids) ? ids : [ids];
options.ids=ids.join(',');
options.ids = ids.join(',');

var qs = querystring.stringify(options);
this.options.fullPath = [this.options.path,this.options.core, this.GET_HANDLER + '?' + qs ]
.filter(function(element){
return element;
})
.join('/');
return queryRequest(this.options,callback);
var query = querystring.stringify(options);
return this.get(this.GET_HANDLER,query,callback);
}

/**
Expand Down Expand Up @@ -188,14 +185,10 @@ Client.prototype.addRemoteResource = function(options,callback){
}else{
options.parameters['stream.file'] = options.path;
}
var path = this.UPDATE_HANDLER + '/' + options.format.toLowerCase() + '?' + querystring.stringify(options.parameters) + '&wt=json';
this.options.fullPath = [this.options.path, this.options.core, path]
.filter(function(element){
if(element) return true;
return false;
})
.join('/');
return queryRequest(this.options,callback);

var handler = this.UPDATE_HANDLER + '/' + options.format.toLowerCase();
var query = querystring.stringify(options.parameters);
return this.get(handler,query,callback);
}

/**
Expand Down Expand Up @@ -492,14 +485,7 @@ Client.prototype.update = function(data,options,callback){
*/

Client.prototype.search = function(query,callback){
// 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, this.SELECT_HANDLER + '?' + parameters + '&wt=json']
.filter(function(element){
return element;
})
.join('/'); ;
return queryRequest(this.options,callback);
return this.get(this.SELECT_HANDLER, query, callback);
}

/**
Expand Down Expand Up @@ -533,14 +519,7 @@ Client.prototype.searchAll = function(callback){
*/

Client.prototype.spell = function(query,callback){
// 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,'spell?' + parameters + '&wt=json']
.filter(function(element){
return element;
})
.join('/'); ;
return queryRequest(this.options,callback);
return this.get(this.SPELL_HANDLER, query, callback);
}

/**
Expand All @@ -556,7 +535,7 @@ Client.prototype.spell = function(query,callback){
* @api public
*/

Client.prototype.get = function(path,query,callback){
Client.prototype.get = function(handler,query,callback){

This comment has been minimized.

Copy link
@marc-portier

marc-portier Jul 30, 2014

Collaborator

@lbdremy
this claimes the get() name for this generic handler instead of using handleGet()
Thus making get() unavailable for my usage in fixing #88 - supporting realtime get mapping onto the /get solr-request-handler.

See also this recent discussions:

I had all this ready up in these branches by the way:

Please advise on how you would want to proceed (i.e. which names to choose for generic handleGet and handelPost - versus realtimeget) so I can adjust my patches.

This comment has been minimized.

Copy link
@marc-portier

marc-portier Jul 30, 2014

Collaborator

ah ok, guess I sassed it now (slow 2nd look) you've added all of that and I can just abandon my patches and use realTimeGet - sorry for the noise

This comment has been minimized.

Copy link
@lbdremy

lbdremy Jul 30, 2014

Author Owner

No worries, first I cherry-picked your commit 26dce54, then I changed the method name to realTimeGet so it matches the name of the feature (I looked at other libraries for solr they call it like that) and it give us the chance to have get method name available to do arbitrary HTTP GET under this name.

if(typeof(query) === 'function'){
callback = query;
var parameters = '';
Expand All @@ -565,7 +544,7 @@ Client.prototype.get = function(path,query,callback){
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,handler + '?' + parameters + '&wt=json']
.filter(function(element){
return element;
})
Expand Down Expand Up @@ -603,12 +582,7 @@ Client.prototype.escapeSpecialChars = format.escapeSpecialChars;
*/

Client.prototype.ping = function(callback){
this.options.fullPath = [this.options.path,this.options.core, this.ADMIN_PING_HANDLER + '?wt=json']
.filter(function(element){
return element;
})
.join('/');
return queryRequest(this.options,callback);
return this.get(this.ADMIN_PING_HANDLER, callback);
}

/**
Expand Down

0 comments on commit 1e85a1a

Please sign in to comment.