Navigation Menu

Skip to content

Commit

Permalink
Use grn_operator_*() API
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 31, 2015
1 parent 838b971 commit c7b936d
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions pgroonga.c
Expand Up @@ -946,38 +946,23 @@ pgroonga_command(PG_FUNCTION_ARGS)
}

static grn_bool
pgroonga_contain_raw(const char *text, unsigned int text_size,
const char *key, unsigned int key_size)
pgroonga_contain_raw(const char *text, unsigned int textSize,
const char *subText, unsigned int subTextSize)
{
grn_bool contained = GRN_FALSE;
grn_obj buffer;
grn_obj *expression, *expressionVariable;

GRN_EXPR_CREATE_FOR_QUERY(ctx, NULL, expression, expressionVariable);

GRN_TEXT_INIT(&buffer, 0);

GRN_TEXT_SET(ctx, &buffer, text, text_size);
grn_expr_append_const(ctx, expression, &buffer, GRN_OP_PUSH, 1);
grn_bool contained;
grn_obj targetBuffer;
grn_obj subTextBuffer;

GRN_TEXT_SET(ctx, &buffer, key, key_size);
grn_expr_append_const(ctx, expression, &buffer, GRN_OP_PUSH, 1);
GRN_TEXT_INIT(&targetBuffer, GRN_OBJ_DO_SHALLOW_COPY);
GRN_TEXT_SET(ctx, &targetBuffer, text, textSize);

grn_expr_append_op(ctx, expression, GRN_OP_MATCH, 2);
GRN_TEXT_INIT(&subTextBuffer, GRN_OBJ_DO_SHALLOW_COPY);
GRN_TEXT_SET(ctx, &subTextBuffer, subText, subTextSize);

{
grn_obj *result;
result = grn_expr_exec(ctx, expression, 0);
if (ctx->rc)
{
goto exit;
}
contained = GRN_INT32_VALUE(result) != 0;
}
contained = grn_operator_exec_match(ctx, &targetBuffer, &subTextBuffer);

exit:
grn_obj_unlink(ctx, expression);
GRN_OBJ_FIN(ctx, &buffer);
GRN_OBJ_FIN(ctx, &targetBuffer);
GRN_OBJ_FIN(ctx, &subTextBuffer);

return contained;
}
Expand Down

0 comments on commit c7b936d

Please sign in to comment.