[Groonga-commit] groonga/gcs [master] BqTranslator: support (field ...)

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 27日 (金) 17:20:22 JST


Kouhei Sutou	2012-07-27 17:20:22 +0900 (Fri, 27 Jul 2012)

  New Revision: 84a72d66ef95958addbc3e7303f12374981e3120
  https://github.com/groonga/gcs/commit/84a72d66ef95958addbc3e7303f12374981e3120

  Log:
    BqTranslator: support (field ...)

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

  Modified: lib/bq-translator.js (+33 -3)
===================================================================
--- lib/bq-translator.js    2012-07-27 17:09:34 +0900 (9a69fa9)
+++ lib/bq-translator.js    2012-07-27 17:20:22 +0900 (f855bb2)
@@ -40,6 +40,9 @@ BooleanQueryTranslator.prototype = {
         this.skipSpaces(query, context);
         var expression;
         switch (operator) {
+        case "field":
+          expression = this.translateGroupField(query, context);
+          break;
         case "and":
           expression = this.translateGroupSetOperation(query, context, "&&");
           break;
@@ -70,6 +73,33 @@ BooleanQueryTranslator.prototype = {
     // TODO: report error: missing close paren <)>
     return "";
   },
+  translateGroupField: function(query, context) {
+    var field = "";
+    for (; context.offset < query.length; context.offset++) {
+      var character = query[context.offset];
+      if (/^[\-a-z0-9]$/.test(character)) {
+        field += character;
+      } else if (character == " ") {
+        this.skipSpaces(query, context);
+        var expression = this.translateExpressionValueString(query, field, context);
+        this.skipSpaces(query, context);
+        if (query[context.offset] != ")") {
+          // TODO: report error: have garbage
+          return "";
+        }
+        return expression;
+      } else if (character == ")") {
+        // TODO: report error: field and value is missing
+        return "";
+      } else {
+        // TODO: report error: invalid field character
+        return "";
+      }
+    }
+
+    // TODO: report error: missing close paren <)>
+    return "";
+  },
   translateGroupSetOperation: function(query, context, setOperator) {
     var expressions = [];
     while (context.offset < query.length) {
@@ -113,9 +143,6 @@ BooleanQueryTranslator.prototype = {
     }
 
     if (query[context.offset] == "'") {
-      if (query[context.offset + 1] == "\"") {
-        return this.translateExpressionValuePhrase(query, field, context);
-      }
       return this.translateExpressionValueString(query, field, context);
     }
     if (/^[0-9]/.test(query[context.offset])) {
@@ -164,6 +191,9 @@ BooleanQueryTranslator.prototype = {
       // TODO: report error
       return "";
     }
+    if (query[context.offset + 1] == "\"") {
+      return this.translateExpressionValuePhrase(query, field, context);
+    }
 
     context.offset++;
     var values = [];

  Modified: test/bq-translator.test.js (+4 -0)
===================================================================
--- test/bq-translator.test.js    2012-07-27 17:09:34 +0900 (fcb022e)
+++ test/bq-translator.test.js    2012-07-27 17:20:22 +0900 (d3a0e21)
@@ -65,6 +65,10 @@ suite('BoolanQueryTranslator', function() {
             '"query query" type:"ModelName"',
             "(and 'query query' type:'ModelName')");
 
+  testGroup("field",
+            "field1 @ \"keyword1\"",
+            "(field field1 'keyword1')".length,
+            "(field field1 'keyword1') (other group)");
   testGroup("and",
             "(field1 @ \"keyword1\" && field2 @ \"keyword2\")",
             "(and field1:'keyword1' field2:'keyword2')".length,
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Descargar 



Groonga-commit メーリングリストの案内
Back to archive index