Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "filtres", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple, safe, ElasticSearch Query compiler", | ||
@@ -5,0 +5,0 @@ "main": "filtres.js", |
@@ -13,4 +13,2 @@ /** | ||
(function () { | ||
"use strict"; | ||
var queryBase = '{"query" : {"filtered" : { "filter": [', | ||
@@ -28,33 +26,39 @@ queryEnd = ']}}}', | ||
} | ||
var tree = compileExpression.parser.parse(expression); | ||
var js = []; | ||
js.push(queryBase); | ||
function toJs(node) { | ||
if (Array.isArray(node)) { | ||
node.forEach(toJs); | ||
} else { | ||
js.push(node); | ||
var tree, queryIsValid = true; | ||
try { | ||
tree = compileExpression.parser.parse(expression); | ||
var js = []; | ||
js.push(queryBase); | ||
function toJs(node) { | ||
if (Array.isArray(node)) { | ||
node.forEach(toJs); | ||
} else { | ||
js.push(node); | ||
} | ||
} | ||
tree.forEach(toJs); | ||
js.push(queryEnd); | ||
} catch (err) { | ||
if (debug) console.log(err); | ||
queryIsValid = false; | ||
} | ||
tree.forEach(toJs); | ||
js.push(queryEnd); | ||
if (debug) console.log(expression, tree, js); | ||
try { | ||
if (queryIsValid) { | ||
return JSON.parse(js.join('')); | ||
} catch (err) { | ||
if (failToQuerystring) { | ||
return { | ||
"query" : { | ||
"query_string" : { | ||
"query": expression.replace(queryCleaner, '') | ||
} | ||
} else if (failToQuerystring) { | ||
return { | ||
"query" : { | ||
"query_string" : { | ||
"query": expression.replace(queryCleaner, '') | ||
} | ||
}; | ||
} else { | ||
if (debug) console.log("ERROR", js.join('')); | ||
throw err; | ||
} | ||
} | ||
}; | ||
} else { | ||
if (debug) console.log("ERROR", js && js.lenght? js.join('') : 'Parse failed'); | ||
throw "Invalid Query"; | ||
} | ||
@@ -61,0 +65,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
369766
7254