Navigation Menu

Skip to content

Commit

Permalink
Bind grn_expr_rewrite()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 7, 2015
1 parent e0a28f7 commit a43d428
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions ext/groonga/rb-grn-expression.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

0 comments on commit a43d428

Please sign in to comment.