[Groonga-commit] groonga/gcs [master] bq: support (not ...)

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Aug 28 12:51:02 JST 2012


Kouhei Sutou	2012-08-28 12:51:02 +0900 (Tue, 28 Aug 2012)

  New Revision: de5b3c12b8f2269001a8eab0ea30ab36f46be379
  https://github.com/groonga/gcs/commit/de5b3c12b8f2269001a8eab0ea30ab36f46be379

  Log:
    bq: support (not ...)
    
    Note that it is heavy query. You should use it carefully.

  Modified files:
    lib/bq-translator.js
    test/bq-translator.test.js

  Modified: lib/bq-translator.js (+13 -3)
===================================================================
--- lib/bq-translator.js    2012-08-27 17:15:32 +0900 (ebeb402)
+++ lib/bq-translator.js    2012-08-28 12:51:02 +0900 (7d1fed6)
@@ -8,9 +8,6 @@
 
   Script syntax grn_expr:
     http://groonga.org/docs/reference/grn_expr/script_syntax.html
-
-  Unsupported syntaxes of Boolean Queries:
-    * (not ...)
 */
 
 var IndexField = require('./database').IndexField;
@@ -110,6 +107,9 @@ BooleanQueryTranslator.prototype = {
         case "and":
           expression = this.translateGroupSetOperation(operator, "&&");
           break;
+        case "not":
+          expression = this.translateGroupNot();
+          break;
         case "or":
           expression = this.translateGroupSetOperation(operator, "||");
           break;
@@ -208,6 +208,16 @@ BooleanQueryTranslator.prototype = {
     this.throwSyntaxError("close parenthesis is missing: " +
                           "operator:<" + label + ">");
   },
+  translateGroupNot: function() {
+    var expression = this.translateExpression();
+    this.skipSpaces();
+    if (this.query[this.offset] == ")") {
+      this.offset++;
+      return "(all_records() &! " + expression + ")";
+    } else {
+      this.throwSyntaxError("close parenthesis is missing: operator:<not>");
+    }
+  },
   translateExpression: function() {
     if (this.query[this.offset] == "(") {
       return this.translateGroup();

  Modified: test/bq-translator.test.js (+8 -0)
===================================================================
--- test/bq-translator.test.js    2012-08-27 17:15:32 +0900 (9871c7f)
+++ test/bq-translator.test.js    2012-08-28 12:51:02 +0900 (43bf265)
@@ -238,10 +238,18 @@ suite('BoolanQueryTranslator', function() {
             "(or field1:'keyword1' field2:'keyword2') (other group)",
             "(or field1:'keyword1' field2:'keyword2')".length,
             "(field1 @ \"keyword1\" || field2 @ \"keyword2\")");
+  testGroup("not",
+            "(not field1:'keyword1') (other group)",
+            "(not field1:'keyword1')".length,
+            "(all_records() &! field1 @ \"keyword1\")");
   testGroup("nested",
             "(and (or field1:'k1' field2:'k2') field3:'k3') (other group)",
             "(and (or field1:'k1' field2:'k2') field3:'k3')".length,
             "((field1 @ \"k1\" || field2 @ \"k2\") && field3 @ \"k3\")");
+  testGroup("not and",
+            "(not (and field1:'k1' field2:'k2')) (other group)",
+            "(not (and field1:'k1' field2:'k2'))".length,
+            "(all_records() &! (field1 @ \"k1\" && field2 @ \"k2\"))");
 
   testGroupError("missing open parentheis",
                  "and field1:'k1' field2:'k2')",
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index