Class: Groonga::RegexpOperator

Inherits:
Operator
  • Object
show all
Defined in:
ext/groonga/rb-grn-regexp-operator.c

Constant Summary

Constants inherited from Operator

Operator::ADJUST, Operator::AND, Operator::AND_ASSIGN, Operator::AND_NOT, Operator::ASSIGN, Operator::BITWISE_AND, Operator::BITWISE_NOT, Operator::BITWISE_OR, Operator::BITWISE_XOR, Operator::BUT, Operator::CALL, Operator::CJUMP, Operator::COMMA, Operator::DECREMENT, Operator::DECREMENT_POST, Operator::DELETE, Operator::EQUAL, Operator::EXACT, Operator::EXPRESSION_GET_VARIABLE, Operator::FUZZY, Operator::GEO_DISTANCE1, Operator::GEO_DISTANCE2, Operator::GEO_DISTANCE3, Operator::GEO_DISTANCE4, Operator::GEO_WITHINP5, Operator::GEO_WITHINP6, Operator::GEO_WITHINP8, Operator::GET_REFERENCE, Operator::GET_VALUE, Operator::GREATER, Operator::GREATER_EQUAL, Operator::IN, Operator::INCREMENT, Operator::INCREMENT_POST, Operator::INTERN, Operator::JSON_PUT, Operator::JUMP, Operator::LESS, Operator::LESS_EQUAL, Operator::LONGEST_COMMON_PREFIX, Operator::MATCH, Operator::MINUS, Operator::MINUS_ASSIGN, Operator::MODULO, Operator::MODULO_ASSIGN, Operator::NEAR, Operator::NEAR2, Operator::NOT, Operator::NOT_EQUAL, Operator::NO_OPERATION, Operator::OBJECT_SEARCH, Operator::OR, Operator::OR_ASSIGN, Operator::PARTIAL, Operator::PLUS, Operator::PLUS_ASSIGN, Operator::POP, Operator::PREFIX, Operator::PUSH, Operator::REGEXP, Operator::SHIFTL, Operator::SHIFTL_ASSIGN, Operator::SHIFTR, Operator::SHIFTRR, Operator::SHIFTRR_ASSIGN, Operator::SHIRTR_ASSIGN, Operator::SIMILAR, Operator::SLASH, Operator::SLASH_ASSIGN, Operator::STAR, Operator::STAR_ASSIGN, Operator::SUFFIX, Operator::TABLE_CREATE, Operator::TABLE_GROUP, Operator::TABLE_SELECT, Operator::TABLE_SORT, Operator::TERM_EXTRACT, Operator::UNSPLIT, Operator::XOR_ASSIGN

Instance Method Summary collapse

Methods inherited from Operator

#initialize, #to_i, #to_s

Constructor Details

This class inherits a constructor from Groonga::Operator

Instance Method Details

#exec(text, regexp, options = {}) ⇒ Boolean

Executes a regular expression match operation.

Examples:

Executes regular expression match operations with the default context

Groonga::Operator::REGEXP.exec("Hello Rroonga", /Rro+nga/) # => true
Groonga::Operator::REGEXP.exec("Hello Rroonga", /Gro+nga/) # => false

Executes regular expression match operations with the specified context

context = Groonga::Context.new
Groonga::Operator::REGEXP.exec("Hello Rroonga", /Rro+nga/,
                             :context => context) # => true
Groonga::Operator::REGEXP.exec("Hello Rroonga", /Gro+nga/,
                             :context => context) # => false

Returns true if text matches regexp, false otherwise.

Parameters:

  • text (String)

    The text to be matched.

  • regexp (Regexp)

    The regular expression.

  • options (::Hash) (defaults to: {})

    The options.

Options Hash (options):

  • (Groonga::Context.default) (Groonga::Context)

    The context to executes the operation.

Returns:

  • (Boolean)

    true if text matches regexp, false otherwise.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'ext/groonga/rb-grn-regexp-operator.c', line 46

static VALUE
rb_grn_regexp_operator_exec (int argc, VALUE *argv, VALUE self)
{
    grn_bool matched;
    VALUE rb_text;
    VALUE rb_regexp;
    VALUE rb_options;
    VALUE rb_context;
    grn_ctx *context;
    grn_obj text;
    grn_obj regexp;

    rb_scan_args(argc, argv, "21", &rb_text, &rb_regexp, &rb_options);

    rb_grn_scan_options(rb_options,
                        "context", &rb_context,
                        NULL);
    context = rb_grn_context_ensure(&rb_context);

    GRN_VOID_INIT(&text);
    GRN_VOID_INIT(&regexp);
    RVAL2GRNBULK(rb_text, context, &text);
    RVAL2GRNBULK(rb_regexp, context, &regexp);
    matched = grn_operator_exec_regexp(context, &text, &regexp);
    GRN_OBJ_FIN(context, &text);
    GRN_OBJ_FIN(context, &regexp);

    return CBOOL2RVAL(matched);
}