Navigation Menu

Skip to content

Commit

Permalink
bq: support and by "+"
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent 36ff8f8 commit 3f6a469
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/bq-translator.js
Expand Up @@ -224,22 +224,20 @@ BooleanQueryTranslator.prototype = {
}

this.offset++;
var values = [];
var tokens = [];
var value = "";
for (; this.offset < this.query.length; this.offset++) {
var character = this.query[this.offset];
if (character == "'") {
this.offset++;
values.push("\"" + value + "\"");
var expressions = values.map(function (value) {
return field + " @ " + value;
});
return expressions.join(" && ");
tokens.push(this.translateExpressionValueStringKeyword(field, value));
return tokens.join(" ");
}

if (character == " ") {
if (character == " " || character == "+") {
if (value.length > 0) {
values.push("\"" + value + "\"");
tokens.push(this.translateExpressionValueStringKeyword(field, value));
tokens.push("&&");
value = "";
}
} else if (character == "\\") {
Expand All @@ -256,6 +254,9 @@ BooleanQueryTranslator.prototype = {
// TODO: report error: missing close quote <'>
return "";
},
translateExpressionValueStringKeyword: function(field, value) {
return field + " @ " + "\"" + value + "\"";
},
translateExpressionValuePhrase: function(field) {
if (!(this.query[this.offset] == "'" &&
this.query[this.offset + 1] == "\"")) {
Expand Down
4 changes: 4 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -109,6 +109,10 @@ suite('BoolanQueryTranslator', function() {
"'keyword1 keyword2' 'other keyword'",
"'keyword1 keyword2'".length,
"field @ \"keyword1\" && field @ \"keyword2\"");
testExpression("value only: stirng: and: +",
"'keyword1+keyword2' 'other keyword'",
"'keyword1+keyword2'".length,
"field @ \"keyword1\" && field @ \"keyword2\"");
testExpression("value only: stirng: phrase",
"'\"keyword1 keyword2\"' 'other keyword'",
"'\"keyword1 keyword2\"'".length,
Expand Down

0 comments on commit 3f6a469

Please sign in to comment.