diff --git a/lib/search-query-parser.js b/lib/search-query-parser.js index d5bd2f1..a81aca1 100644 --- a/lib/search-query-parser.js +++ b/lib/search-query-parser.js @@ -27,8 +27,14 @@ exports.parse = function (string, options) { else { // Our object to store the query object var query = {text: []}; - // Get a list of search term. Reverse to ensure proper order when pop()'ing. - var terms = string.split(' ').reverse(); + // Get a list of search terms respecting single and double quotes + var terms = string.match(/(\S+:(".+?"|'.+?'))|(\S+:\S+)|\S+/g); + // Rip out the quotes + for (var i = 0; i < terms.length; i++) { + terms[i] = terms[i].replace(/['"]+/g, ''); + }; + // Reverse to ensure proper order when pop()'ing. + terms.reverse(); // For each search term while (term = terms.pop()) { // Advanced search terms syntax has key and value