Navigation Menu

Skip to content

Commit

Permalink
bq: support label operator for q
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2012
1 parent a9a4ac7 commit a62050f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/bq-translator.js
Expand Up @@ -72,6 +72,15 @@ BooleanQueryTranslator.prototype = {
this.skipSpaces();
var expression;
switch (operator) {
case "label":
expression = this.translateExpression();
this.skipSpaces();
if (this.query[this.offset] != ")") {
this.throwTranslateError("close parenthesis is missing: " +
"operator:<label>");
}
this.offset++;
break;
case "field":
expression = this.translateGroupField();
break;
Expand Down
9 changes: 9 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -161,11 +161,20 @@ suite('BoolanQueryTranslator', function() {
"(and 'keyword1 keyword2' type:'ModelName')",
'(field @ "keyword1" && field @ "keyword2" && type @ "ModelName")');

testQuery("label",
"(label 'keyword1 keyword2')",
'field @ "keyword1" && field @ "keyword2"');

testQueryError("garbage",
"(and 'keyword' type:'ModelName') garbage1 garbage2",
"(and 'keyword' type:'ModelName')| |garbage1 garbage2",
"garbages exist after valid boolean query");

testQueryError("label: missing close parentheis",
"(label 'keyword1 keyword2'",
"(label 'keyword1 keyword2'||",
"close parenthesis is missing: operator:<label>");

testGroup("field",
"(field field1 'keyword1') (other group)",
"(field field1 'keyword1')".length,
Expand Down

0 comments on commit a62050f

Please sign in to comment.