doofinder
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -69,7 +69,24 @@ | ||
Doofinder.prototype.search = function(params, callback) { | ||
var filter_key, filter_terms, headers, options, param_key, param_value, process_response, query_string, req; | ||
Doofinder.prototype.search = function(query, arg1, arg2) { | ||
var callback, filter_key, filter_terms, headers, options, param_key, param_value, params, process_response, query_string, req; | ||
if (arg1 && arg1.constructor === Function) { | ||
callback = arg1; | ||
params = {}; | ||
} else if (arg1 && arg2 && arg1.constructor === Object) { | ||
callback = arg2; | ||
params = arg1; | ||
} else { | ||
throw new Error("A callback is required."); | ||
} | ||
if (params.page == null) { | ||
params.page = 1; | ||
} | ||
if (params.rpp == null) { | ||
params.rpp = 10; | ||
} | ||
params.query = query; | ||
headers = {}; | ||
this.params = {}; | ||
this.filters = {}; | ||
this.sort = []; | ||
for (param_key in params) { | ||
@@ -82,2 +99,4 @@ param_value = params[param_key]; | ||
} | ||
} else if (param_key === "sort") { | ||
this.set_sort(param_value); | ||
} else { | ||
@@ -122,3 +141,3 @@ if (param_value) { | ||
/* | ||
set_param | ||
add_param | ||
@@ -151,2 +170,16 @@ This method set simple params | ||
/* | ||
set_sort | ||
This method adds sort to object | ||
from an object or an array | ||
@param {Array|Object} sort | ||
*/ | ||
Doofinder.prototype.set_sort = function(sort) { | ||
return this.sort = sort; | ||
}; | ||
/* | ||
make_querystring | ||
@@ -163,3 +196,3 @@ | ||
Doofinder.prototype.make_querystring = function() { | ||
var elem, i, key, len, querystring, ref, ref1, value; | ||
var elem, facet, i, key, len, querystring, ref, ref1, ref2, ref3, term, value; | ||
querystring = "hashid=" + this.hashid; | ||
@@ -185,2 +218,19 @@ ref = this.params; | ||
} | ||
if (this.sort && this.sort.constructor === Array) { | ||
ref2 = this.sort; | ||
for (key in ref2) { | ||
value = ref2[key]; | ||
for (facet in value) { | ||
term = value[facet]; | ||
querystring += "&sort[" + key + "][" + facet + "]=" + term; | ||
} | ||
} | ||
} else if (this.sort && this.sort.constructor === Object) { | ||
ref3 = this.sort; | ||
for (key in ref3) { | ||
value = ref3[key]; | ||
querystring += "&sort[" + key + "]=" + value; | ||
} | ||
} | ||
console.log(encodeURI(querystring)); | ||
return encodeURI(querystring); | ||
@@ -187,0 +237,0 @@ }; |
{ | ||
"name": "doofinder", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Javascript Client for Doofinder Search API - Beta", | ||
@@ -5,0 +5,0 @@ "main": "lib/doofinder.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10384
6
202