Permalink
Browse files

Added faceting support in query()

  • Loading branch information...
1 parent 739208f commit 5e00a2118c4041794202de71f1386b928fdc9a53 @VasylMarchuk VasylMarchuk committed Apr 5, 2011
Showing with 20 additions and 0 deletions.
  1. +20 −0 lib/solr.js
View
@@ -93,7 +93,27 @@ Client.prototype.query = function(query, options, callback) {
var queryParams = options || {};
queryParams.q = query;
queryParams.wt = "json";
+
+ var facets;
+ if('facets' in queryParams) {
+ facets = queryParams.facets;
+ delete queryParams['facets'];
+ queryParams.facet = true;
+ }
+
queryParams = querystring.stringify(queryParams, '&', '=', false);
+
+ if(facets) {
+ for(var field in facets) {
+ var opts = facets[field];
+ var fopts = {};
+ for(var o in opts) {
+ fopts['f.'+field+'.facet.'+o] = opts[o];
+ }
+ queryParams += '&facet.field=' + field + '&' + querystring.stringify(fopts, '&', '=', false);
+ }
+ }
+
this.rawQuery(queryParams, callback);
};

0 comments on commit 5e00a21

Please sign in to comment.