X-Git-Url: http://git.indexdata.com/?p=cql-js-moved-to-github.git;a=blobdiff_plain;f=cql.js;h=ebd878e71de519ce95f0fe9e0ff312cd950754a4;hp=ebd5e766615c4af2e540faec1dc634161314bf84;hb=549d7685dd4fe9ac422f0cbfdee3d0c604ad7173;hpb=0b0b8b4fae0f58ab263e03c1cffe2dd819a6d891 diff --git a/cql.js b/cql.js index ebd5e76..ebd878e 100644 --- a/cql.js +++ b/cql.js @@ -4,7 +4,6 @@ function indent(n) { s = s + " "; return s; } - // CQLModifier var CQLModifier = function () { this.name = null; @@ -24,8 +23,17 @@ CQLModifier.prototype = { + "" + this.value +"\n"; s = s + indent(n+1) + "\n"; return s; + }, + + toFQ: function () { + //we ignore modifier relation symbol, for value-less modifiers + //we assume 'true' + var value = this.value.length > 0 ? this.value : "true"; + var s = '"'+this.name+'": "'+value+'"'; + return s; } } + // CQLSearchClause var CQLSearchClause = function (field, fielduri, relation, relationuri, modifiers, term) { @@ -66,7 +74,38 @@ CQLSearchClause.prototype = { s = s + indent(n+1) + "" + this.term + "\n"; s = s + indent(n) + "\n"; return s; + }, + + toFQ: function () { + var s = '{ "term": "'+this.term+'"'; + if (this.field.length > 0 && this.field != 'cql.serverChoice') + s+= ', "field": "'+this.field+'"'; + if (this.relation.length > 0 && this.relation != 'scr') + s+= ', "relation": "'+this._mapRelation(this.relation)+'"'; + for (var i = 0; i < this.modifiers.length; i++) { + //since modifiers are mapped to keys, ignore the reserved ones + if (this.modifiers[i].name == "term" + ||this.modifiers[i].name == "field" + ||this.modifiers[i].name == "relation") + continue; + s += ', ' + this.modifiers[i].toFQ(); + } + s += ' }'; + return s; + }, + + _mapRelation: function (rel) { + switch(rel) { + case "<" : return "lt"; + case ">" : return "gt"; + case "=" : return "eq"; + case "<>" : return "ne"; + case ">=" : return "ge"; + case "<=" : return "le"; + default: return rel; + } } + } // CQLBoolean var CQLBoolean = function() { @@ -95,7 +134,19 @@ CQLBoolean.prototype = { this.right.toXCQL(n+2) + indent(n+1) + "\n"; s = s + indent(n) + "\n"; return s; + }, + + toFQ: function () { + var s = ' { "op": "'+this.op+'"'; + //proximity modifiers + for (var i = 0; i < this.modifiers.length; i++) + s += ', ' + this.modifiers[i].toFQ(); + s += ', "s1": '+this.left.toFQ(); + s += ', "s2": '+this.right.toFQ(); + s += ' }' + return s; } + } // CQLParser var CQLParser = function () { @@ -125,6 +176,9 @@ CQLParser.prototype = { toXCQL: function () { return this.tree.toXCQL(); }, + toFQ: function () { + return this.tree.toFQ(); + }, _parseQuery: function(field, relation, modifiers) { var left = this._parseSearchClause(field, relation, modifiers); while (this.look == "s" && (