Skip to content

Instantly share code, notes, and snippets.

@erberg-snippets
Last active December 26, 2015 19:49
Show Gist options
  • Save erberg-snippets/7203768 to your computer and use it in GitHub Desktop.
Save erberg-snippets/7203768 to your computer and use it in GitHub Desktop.
/**
* Build a SOLR query using kay-value pairs from queryObject.
* @param {Object} queryObject Object conaining the name and value for each search parameter.
* @return {String} Query string to be appended to URL
*/
function buildSOLRQuery(queryObject) {
var queryString = '';
for (key in queryObject) {
if (queryObject[key] !== '') {
queryString += (queryString ? ' AND ' : '') + //If queryString is not empty, add '&' at the beginning
key + ':' + queryObject[key];
}
}
return queryString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment