[Groonga-commit] ranguba/rroonga at a43d428 [master] Bind grn_expr_rewrite()

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Oct 7 18:37:23 JST 2015


Kouhei Sutou	2015-10-07 18:37:23 +0900 (Wed, 07 Oct 2015)

  New Revision: a43d428e9480e6c00a4675929fb62de98af64970
  https://github.com/ranguba/rroonga/commit/a43d428e9480e6c00a4675929fb62de98af64970

  Message:
    Bind grn_expr_rewrite()

  Modified files:
    .travis.yml
    ext/groonga/rb-grn-expression.c

  Modified: .travis.yml (+2 -2)
===================================================================
--- .travis.yml    2015-10-07 14:05:42 +0900 (530a1ec)
+++ .travis.yml    2015-10-07 18:37:23 +0900 (6e89e04)
@@ -7,8 +7,8 @@ rvm:
   - 2.1
   - 2.2
   - ruby-head
-# env:
-#   - GROONGA_MASTER=yes
+env:
+  - GROONGA_MASTER=yes
 # matrix:
 #   allow_failures:
 #     - rvm: ruby-head

  Modified: ext/groonga/rb-grn-expression.c (+34 -0)
===================================================================
--- ext/groonga/rb-grn-expression.c    2015-10-07 14:05:42 +0900 (ae20d55)
+++ ext/groonga/rb-grn-expression.c    2015-10-07 18:37:23 +0900 (92d8027)
@@ -824,6 +824,37 @@ rb_grn_expression_estimate_size (VALUE self)
     return UINT2NUM(size);
 }
 
+/*
+ * Rewrites expression.
+ *
+ * @example
+ *   expression.parse("age >= 10 AND age < 20",
+ *                    :syntax => :script)
+ *   expression.rewrite # => New rewritten expression.
+ *                      #    It'll use between(age, 10, "include", 20, "exclude")
+ *
+ * @overload rewrite
+ *   @return [Groonga::Expression, nil] new rewritten expression when
+ *      the expression is rewritten, `nil` otherwise.
+ *
+ * @since 5.1.0
+ */
+static VALUE
+rb_grn_expression_rewrite (VALUE self)
+{
+    grn_ctx *context = NULL;
+    grn_obj *expression;
+    grn_obj *rewritten_expression;
+
+    rb_grn_expression_deconstruct(SELF(self), &expression, &context,
+                                  NULL, NULL,
+                                  NULL, NULL, NULL);
+
+    rewritten_expression = grn_expr_rewrite(context, expression);
+
+    return GRNOBJECT2RVAL(Qnil, context, rewritten_expression, GRN_TRUE);
+}
+
 void
 rb_grn_init_expression (VALUE mGrn)
 {
@@ -865,4 +896,7 @@ rb_grn_init_expression (VALUE mGrn)
 
     rb_define_method(rb_cGrnExpression, "estimate_size",
                      rb_grn_expression_estimate_size, 0);
+
+    rb_define_method(rb_cGrnExpression, "rewrite",
+                     rb_grn_expression_rewrite, 0);
 }
-------------- next part --------------
HTML����������������������������...
Download 



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