[Groonga-commit] groonga/groonga at 43018c4 [master] mrb: add Expression#parse

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Feb 3 15:38:59 JST 2015


Kouhei Sutou	2015-02-03 15:38:59 +0900 (Tue, 03 Feb 2015)

  New Revision: 43018c47679af80cbd6f83183f2c7f5248c36f22
  https://github.com/groonga/groonga/commit/43018c47679af80cbd6f83183f2c7f5248c36f22

  Message:
    mrb: add Expression#parse

  Modified files:
    lib/mrb/mrb_expr.c

  Modified: lib/mrb/mrb_expr.c (+37 -0)
===================================================================
--- lib/mrb/mrb_expr.c    2015-02-03 15:34:51 +0900 (59d7fad)
+++ lib/mrb/mrb_expr.c    2015-02-03 15:38:59 +0900 (cfcbc1d)
@@ -25,6 +25,7 @@
 #include <mruby/data.h>
 #include <mruby/string.h>
 #include <mruby/array.h>
+#include <mruby/hash.h>
 
 #include "../grn_expr.h"
 #include "../grn_util.h"
@@ -444,6 +445,39 @@ mrb_grn_expression_allocate_constant(mrb_state *mrb, mrb_value self)
   return grn_mrb_value_from_grn_obj(mrb, grn_object);
 }
 
+static mrb_value
+mrb_grn_expression_parse(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_obj *expr;
+  char *query;
+  mrb_int query_size;
+  grn_obj *default_column = NULL;
+  grn_operator default_mode = GRN_OP_MATCH;
+  grn_operator default_operator = GRN_OP_AND;
+  grn_expr_flags flags = GRN_EXPR_SYNTAX_SCRIPT;
+  mrb_value mrb_options;
+
+  expr = DATA_PTR(self);
+  mrb_get_args(mrb, "s|H", &query, &query_size, &mrb_options);
+
+  if (!mrb_nil_p(mrb_options)) {
+    mrb_value mrb_flags;
+
+    mrb_flags = mrb_hash_get(mrb, mrb_options,
+                             mrb_symbol_value(mrb_intern_lit(mrb, "flags")));
+    if (!mrb_nil_p(mrb_flags)) {
+      flags = mrb_fixnum(mrb_flags);
+    }
+  }
+
+  grn_expr_parse(ctx, expr, query, query_size, default_column,
+                 default_mode, default_operator, flags);
+  grn_mrb_ctx_check(mrb);
+
+  return mrb_nil_value();
+}
+
 void
 grn_mrb_expr_init(grn_ctx *ctx)
 {
@@ -519,6 +553,9 @@ grn_mrb_expr_init(grn_ctx *ctx)
   mrb_define_method(mrb, klass, "allocate_constant",
                     mrb_grn_expression_allocate_constant, MRB_ARGS_REQ(1));
 
+  mrb_define_method(mrb, klass, "parse",
+                    mrb_grn_expression_parse, MRB_ARGS_ARG(1, 1));
+
   grn_mrb_load(ctx, "expression.rb");
   grn_mrb_load(ctx, "scan_info.rb");
   grn_mrb_load(ctx, "scan_info_data.rb");
-------------- next part --------------
HTML����������������������������...
다운로드 



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