Navigation Menu

Skip to content

Commit

Permalink
Use "==" operator to search literal fields
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 23, 2012
1 parent 7d762bc commit 16f7ccb
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/bq-translator.js
Expand Up @@ -13,6 +13,7 @@
* (not ...)
*/

var IndexField = require('./database').IndexField;

function BooleanQueryTranslator(query) {
this.query = query;
Expand Down Expand Up @@ -226,6 +227,7 @@ BooleanQueryTranslator.prototype = {
this.offset++;

var tokens = [];
var type = field ? this.getField(field).type : "text" ;
var value = "";
var self = this;
var addKeywordToken = function() {
Expand All @@ -252,8 +254,12 @@ BooleanQueryTranslator.prototype = {
}

if (character == " " || character == "+") {
addKeywordToken();
tokens.push("&&");
if (type == "literal") {
value += character;
} else {
addKeywordToken();
tokens.push("&&");
}
} else if (character == "|") {
addKeywordToken();
tokens.push("||");
Expand All @@ -280,10 +286,15 @@ BooleanQueryTranslator.prototype = {
this.throwTranslateError("close single quote for string value is missing");
},
translateExpressionValueStringKeyword: function(field, value) {
var operator = "@";
if (value[value.length - 1] == "*") {
operator = "@^";
value = value.substring(0, value.length - 1);
var operator;
if (!field || this.getField(field).type == "text") {
operator = "@";
if (value[value.length - 1] == "*") {
operator = "@^";
value = value.substring(0, value.length - 1);
}
} else {
operator = "==";
}
return this.constructBinaryOperation(field, operator, "\"" + value + "\"");
},
Expand Down Expand Up @@ -390,6 +401,14 @@ BooleanQueryTranslator.prototype = {
return expressions[0];
}
}
},
getField: function(fieldName) {
var field;
if (this.domain)
field = this.domain.getIndexField(fieldName);
if (!field)
field = new IndexField(fieldName).setType("text");
return field;
}
};

Expand Down

0 comments on commit 16f7ccb

Please sign in to comment.