本文整理匯總了C++中GRN_TEXT_INIT函數的典型用法代碼示例。如果您正苦於以下問題:C++ GRN_TEXT_INIT函數的具體用法?C++ GRN_TEXT_INIT怎麽用?C++ GRN_TEXT_INIT使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GRN_TEXT_INIT函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: update_data
static void
update_data(grn_id record_id, unsigned int section,
const gchar *old_name, const gchar *new_name)
{
grn_obj old_value, new_value;
const gchar *old_data, *new_data;
GRN_TEXT_INIT(&old_value, GRN_OBJ_DO_SHALLOW_COPY);
GRN_TEXT_INIT(&new_value, GRN_OBJ_DO_SHALLOW_COPY);
if (old_name) {
old_data = cut_get_fixture_data_string(old_name, NULL);
GRN_TEXT_SET_REF(&old_value, old_data, strlen(old_data));
}
if (new_name) {
new_data = cut_get_fixture_data_string(new_name, NULL);
GRN_TEXT_SET_REF(&new_value, new_data, strlen(new_data));
}
grn_ii_column_update(context, inverted_index, record_id, section,
&old_value, &new_value, NULL);
grn_obj_close(context, &old_value);
grn_obj_close(context, &new_value);
}
示例2: grn_test_view_collect_string
const GList *
grn_test_view_collect_string(grn_ctx *context,
grn_obj *view,
const gchar *text_column_name)
{
GList *records = NULL;
grn_table_cursor *cursor;
grn_obj id, value;
grn_obj *text_column;
cursor = grn_table_cursor_open(context, view, NULL, 0, NULL, 0,
0, -1, GRN_CURSOR_ASCENDING);
cut_assert_not_null(cursor);
GRN_TEXT_INIT(&id, 0);
GRN_TEXT_INIT(&value, 0);
text_column = grn_obj_column(context, view,
text_column_name, strlen(text_column_name));
while (grn_table_cursor_next_o(context, cursor, &id) == GRN_SUCCESS) {
GRN_BULK_REWIND(&value);
grn_obj_get_value_o(context, text_column, &id, &value);
records = g_list_append(records, g_strndup(GRN_TEXT_VALUE(&value),
GRN_TEXT_LEN(&value)));
}
grn_obj_unlink(context, &id);
grn_obj_unlink(context, &value);
grn_obj_unlink(context, text_column);
gcut_take_list(records, g_free);
grn_test_assert(grn_table_cursor_close(context, cursor));
grn_test_assert_context(context);
return records;
}
示例3: table_put2
int
table_put2(void)
{
int i;
grn_obj keybuf, valbuf;
grn_obj *key_type = grn_ctx_at(&ctx, GRN_DB_SHORT_TEXT);
grn_obj *table = grn_table_create(&ctx, "<t1>", 4, NULL,
GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_PERSISTENT,
key_type, value_type);
if (!table) { return -1; }
for (i = 0; i < nloops; i++) {
int key = GENKEY(i);
GRN_TEXT_INIT(&keybuf, 0);
grn_text_itoh(&ctx, &keybuf, key, key_size);
{
grn_id rid = grn_table_add(&ctx, table, GRN_BULK_HEAD(&keybuf), key_size, NULL);
if (!rid) {
fprintf(stderr, "table_lookup failed");
} else {
GRN_TEXT_INIT(&valbuf, 0);
grn_text_itoh(&ctx, &valbuf, key, key_size);
if (grn_obj_set_value(&ctx, table, rid, &valbuf, GRN_OBJ_SET)) {
fprintf(stderr, "grn_obj_set_value failed");
}
grn_obj_close(&ctx, &valbuf);
}
}
grn_obj_close(&ctx, &keybuf);
}
return 0;
}
示例4: table_get
int
table_get(void)
{
int i;
grn_obj buf;
grn_obj *table = grn_ctx_get(&ctx, "<t1>", 4);
if (!table) { return -1; }
GRN_TEXT_INIT(&buf, 0);
for (i = 0; i < nloops; i++) {
int key = GENKEY(i);
GRN_BULK_REWIND(&buf);
grn_text_itoh(&ctx, &buf, key, key_size);
{
grn_id rid = grn_table_get(&ctx, table, GRN_BULK_HEAD(&buf), key_size);
if (!rid) {
fprintf(stderr, "table_lookup failed");
} else {
grn_obj obj, *p;
GRN_TEXT_INIT(&obj, 0);
p = grn_obj_get_value(&ctx, table, rid, &obj);
if (!p) {
fprintf(stderr, "grn_obj_get_value failed\n");
} else {
if (memcmp(GRN_BULK_HEAD(p), GRN_BULK_HEAD(&buf), value_size)) {
fprintf(stderr, "value unmatch\n");
}
grn_obj_close(&ctx, p);
}
}
}
}
grn_obj_close(&ctx, &buf);
return 0;
}
示例5: report_set_column_value_failure
static void
report_set_column_value_failure(grn_ctx *ctx,
grn_obj *key,
const char *column_name,
unsigned int column_name_size,
grn_obj *column_value)
{
grn_obj key_inspected, column_value_inspected;
GRN_TEXT_INIT(&key_inspected, 0);
GRN_TEXT_INIT(&column_value_inspected, 0);
grn_inspect_limited(ctx, &key_inspected, key);
grn_inspect_limited(ctx, &column_value_inspected, column_value);
GRN_LOG(ctx, GRN_LOG_ERROR,
"[table][load] failed to set column value: %s: "
"key: <%.*s>, column: <%.*s>, value: <%.*s>",
ctx->errbuf,
(int)GRN_TEXT_LEN(&key_inspected),
GRN_TEXT_VALUE(&key_inspected),
column_name_size,
column_name,
(int)GRN_TEXT_LEN(&column_value_inspected),
GRN_TEXT_VALUE(&column_value_inspected));
GRN_OBJ_FIN(ctx, &key_inspected);
GRN_OBJ_FIN(ctx, &column_value_inspected);
}
示例6: grn_tokenizer_register
grn_rc
grn_tokenizer_register(grn_ctx *ctx, const char *plugin_name_ptr,
unsigned int plugin_name_length,
grn_proc_func *init, grn_proc_func *next,
grn_proc_func *fin)
{
grn_expr_var vars[] = {
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 }
};
GRN_TEXT_INIT(&vars[0].value, 0);
GRN_TEXT_INIT(&vars[1].value, 0);
GRN_UINT32_INIT(&vars[2].value, 0);
{
/*
grn_proc_create() registers a plugin to the database which is associated
with `ctx'. A returned object must not be finalized here.
*/
grn_obj * const obj = grn_proc_create(ctx, plugin_name_ptr,
plugin_name_length,
GRN_PROC_TOKENIZER,
init, next, fin, 3, vars);
if (obj == NULL) {
GRN_PLUGIN_ERROR(ctx, GRN_TOKENIZER_ERROR, "grn_proc_create() failed");
return ctx->rc;
}
}
return GRN_SUCCESS;
}
示例7: load_synonyms
static void
load_synonyms(grn_ctx *ctx)
{
static char path_env[GRN_ENV_BUFFER_SIZE];
const char *path;
grn_file_reader *file_reader;
int number_of_lines;
grn_encoding encoding;
grn_obj line, key, value;
grn_getenv("GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE",
path_env,
GRN_ENV_BUFFER_SIZE);
if (path_env[0]) {
path = path_env;
} else {
path = get_system_synonyms_file();
}
file_reader = grn_file_reader_open(ctx, path);
if (!file_reader) {
GRN_LOG(ctx, GRN_LOG_WARNING,
"[plugin][query-expander][tsv] "
"synonyms file doesn't exist: <%s>",
path);
return;
}
GRN_TEXT_INIT(&line, 0);
GRN_TEXT_INIT(&key, 0);
GRN_TEXT_INIT(&value, 0);
grn_bulk_reserve(ctx, &value, MAX_SYNONYM_BYTES);
number_of_lines = 0;
while (grn_file_reader_read_line(ctx, file_reader, &line) == GRN_SUCCESS) {
const char *line_value = GRN_TEXT_VALUE(&line);
size_t line_length = GRN_TEXT_LEN(&line);
if (line_length > 0 && line_value[line_length - 1] == '\n') {
if (line_length > 1 && line_value[line_length - 2] == '\r') {
line_length -= 2;
} else {
line_length -= 1;
}
}
number_of_lines++;
if (number_of_lines == 1) {
encoding = guess_encoding(ctx, &line_value, &line_length);
}
GRN_BULK_REWIND(&key);
GRN_BULK_REWIND(&value);
parse_synonyms_file_line(ctx, line_value, line_length, &key, &value);
GRN_BULK_REWIND(&line);
}
GRN_OBJ_FIN(ctx, &line);
GRN_OBJ_FIN(ctx, &key);
GRN_OBJ_FIN(ctx, &value);
grn_file_reader_close(ctx, file_reader);
}
示例8: grn_token_cursor_next_apply_token_filters
static int
grn_token_cursor_next_apply_token_filters(grn_ctx *ctx,
grn_token_cursor *token_cursor,
grn_obj *current_token_data,
grn_obj *status)
{
grn_obj *token_filters = token_cursor->token_filter.objects;
unsigned int i, n_token_filters;
grn_token current_token;
grn_token next_token;
if (token_filters) {
n_token_filters = GRN_BULK_VSIZE(token_filters) / sizeof(grn_obj *);
} else {
n_token_filters = 0;
}
GRN_TEXT_INIT(&(current_token.data), GRN_OBJ_DO_SHALLOW_COPY);
GRN_TEXT_SET(ctx, &(current_token.data),
GRN_TEXT_VALUE(current_token_data),
GRN_TEXT_LEN(current_token_data));
current_token.status = GRN_INT32_VALUE(status);
GRN_TEXT_INIT(&(next_token.data), GRN_OBJ_DO_SHALLOW_COPY);
GRN_TEXT_SET(ctx, &(next_token.data),
GRN_TEXT_VALUE(&(current_token.data)),
GRN_TEXT_LEN(&(current_token.data)));
next_token.status = current_token.status;
for (i = 0; i < n_token_filters; i++) {
grn_obj *token_filter_object = GRN_PTR_VALUE_AT(token_filters, i);
grn_proc *token_filter = (grn_proc *)token_filter_object;
void *data = token_cursor->token_filter.data[i];
#define SKIP_FLAGS\
(GRN_TOKEN_SKIP |\
GRN_TOKEN_SKIP_WITH_POSITION)
if (current_token.status & SKIP_FLAGS) {
break;
}
#undef SKIP_FLAGS
token_filter->callbacks.token_filter.filter(ctx,
¤t_token,
&next_token,
data);
GRN_TEXT_SET(ctx, &(current_token.data),
GRN_TEXT_VALUE(&(next_token.data)),
GRN_TEXT_LEN(&(next_token.data)));
current_token.status = next_token.status;
}
token_cursor->curr =
(const unsigned char *)GRN_TEXT_VALUE(&(current_token.data));
token_cursor->curr_size = GRN_TEXT_LEN(&(current_token.data));
return current_token.status;
}
示例9: command_tag_synonym_delete
static grn_obj *
command_tag_synonym_delete(grn_ctx *ctx, GNUC_UNUSED int nargs, GNUC_UNUSED grn_obj **args,
grn_user_data *user_data)
{
grn_obj *var, *table, *column;
unsigned int nhooks = 0;
char *table_name = NULL;
unsigned int table_len = 0;
char *column_name = NULL;
unsigned int column_len = 0;
var = grn_plugin_proc_get_var(ctx, user_data, "table", -1);
if (GRN_TEXT_LEN(var) != 0) {
table_name = GRN_TEXT_VALUE(var);
table_len = GRN_TEXT_LEN(var);
}
var = grn_plugin_proc_get_var(ctx, user_data, "column", -1);
if (GRN_TEXT_LEN(var) != 0) {
column_name = GRN_TEXT_VALUE(var);
column_len = GRN_TEXT_LEN(var);
}
table = grn_ctx_get(ctx, table_name, table_len);
column = grn_obj_column(ctx, table, column_name, column_len);
nhooks = grn_obj_get_nhooks(ctx, column, GRN_HOOK_SET);
if (nhooks) {
grn_obj *hook;
unsigned int i;
grn_obj data;
grn_obj buf;
GRN_TEXT_INIT(&buf, 0);
GRN_TEXT_INIT(&data, 0);
for (i=0; i < nhooks; i++) {
GRN_BULK_REWIND(&buf);
GRN_BULK_REWIND(&data);
hook = grn_obj_get_hook(ctx, column, GRN_HOOK_SET, i, &data);
grn_inspect_name(ctx, &buf, hook);
if (GRN_TEXT_LEN(&buf) == strlen("tag_synonym") &&
strncmp(GRN_TEXT_VALUE(&buf), "tag_synonym", GRN_TEXT_LEN(&buf)) == 0) {
grn_obj_delete_hook(ctx, column, GRN_HOOK_SET, i);
break;
}
}
grn_obj_unlink(ctx, &data);
grn_obj_unlink(ctx, &buf);
}
nhooks = grn_obj_get_nhooks(ctx, column, GRN_HOOK_SET);
//grn_ctx_output_array_open(ctx, "RESULT", 1);
grn_ctx_output_int32(ctx, nhooks);
//grn_ctx_output_array_close(ctx);
return NULL;
}
示例10: ngx_http_groonga_handler_create_data
static ngx_int_t
ngx_http_groonga_handler_create_data(ngx_http_request_t *r,
ngx_http_groonga_handler_data_t **data_return)
{
ngx_int_t rc;
ngx_http_groonga_loc_conf_t *location_conf;
ngx_http_cleanup_t *cleanup;
ngx_http_groonga_handler_data_t *data;
grn_ctx *context;
location_conf = ngx_http_get_module_loc_conf(r, ngx_http_groonga_module);
cleanup = ngx_http_cleanup_add(r, sizeof(ngx_http_groonga_handler_data_t));
cleanup->handler = ngx_http_groonga_handler_cleanup;
data = cleanup->data;
*data_return = data;
context = &(data->context);
rc = ngx_http_groonga_context_init(context, location_conf,
r->pool, r->connection->log);
if (rc != NGX_OK) {
return rc;
}
data->initialized = GRN_TRUE;
data->raw.processed = GRN_FALSE;
data->raw.header_sent = GRN_FALSE;
data->raw.r = r;
data->raw.rc = NGX_OK;
data->raw.free_chain = NULL;
data->raw.busy_chain = NULL;
GRN_TEXT_INIT(&(data->typed.head), GRN_NO_FLAGS);
GRN_TEXT_INIT(&(data->typed.body), GRN_NO_FLAGS);
GRN_TEXT_INIT(&(data->typed.foot), GRN_NO_FLAGS);
grn_ctx_use(context, grn_ctx_db(&(location_conf->context)));
rc = ngx_http_groonga_context_check_error(r->connection->log, context);
if (rc != NGX_OK) {
return rc;
}
grn_ctx_recv_handler_set(context,
ngx_http_groonga_context_receive_handler,
data);
return NGX_OK;
}
示例11: mroonga_escape_init
MRN_API my_bool mroonga_escape_init(UDF_INIT *initid, UDF_ARGS *args,
char *message)
{
EscapeInfo *info = NULL;
initid->ptr = NULL;
if (!(1 <= args->arg_count && args->arg_count <= 2)) {
sprintf(message,
"mroonga_escape(): Incorrect number of arguments: %u for 1..2",
args->arg_count);
goto error;
}
if (args->arg_type[0] != STRING_RESULT) {
strcpy(message,
"mroonga_escape(): The 1st argument must be query as string");
goto error;
}
if (args->arg_count == 2) {
if (args->arg_type[1] != STRING_RESULT) {
strcpy(message,
"mroonga_escape(): "
"The 2st argument must be escape target characters as string");
goto error;
}
}
initid->maybe_null = 1;
initid->const_item = 0;
info = (EscapeInfo *)mrn_my_malloc(sizeof(EscapeInfo),
MYF(MY_WME | MY_ZEROFILL));
if (!info) {
strcpy(message, "mroonga_escape(): out of memory");
goto error;
}
grn_ctx_init(&(info->ctx), 0);
GRN_TEXT_INIT(&(info->target_characters), 0);
GRN_TEXT_INIT(&(info->escaped_query), 0);
initid->ptr = (char *)info;
return FALSE;
error:
if (info) {
grn_ctx_fin(&(info->ctx));
my_free(info);
}
return TRUE;
}
示例12: grn_command_input_add
grn_obj *
grn_command_input_add(grn_ctx *ctx,
grn_command_input *input,
const char *name,
int name_size,
grn_bool *added)
{
grn_obj *argument = NULL;
/* TODO: Use grn_bool */
int internal_added = GRN_FALSE;
GRN_API_ENTER;
if (name_size == -1) {
name_size = strlen(name);
}
if (input->arguments) {
grn_hash_add(ctx, input->arguments, name, name_size, (void **)&argument,
&internal_added);
if (internal_added) {
GRN_TEXT_INIT(argument, 0);
}
}
if (added) {
*added = internal_added;
}
GRN_API_RETURN(argument);
}
示例13: delimited_init
static grn_obj *
delimited_init(grn_ctx *ctx, grn_obj *table, grn_user_data *user_data,
uint8_t *delimiter, uint32_t delimiter_len)
{
grn_obj *str;
int nflags = 0;
grn_delimited_tokenizer *token;
grn_obj_flags table_flags;
if (!(str = grn_ctx_pop(ctx))) {
ERR(GRN_INVALID_ARGUMENT, "missing argument");
return NULL;
}
if (!(token = GRN_MALLOC(sizeof(grn_delimited_tokenizer)))) { return NULL; }
user_data->ptr = token;
token->delimiter = delimiter;
token->delimiter_len = delimiter_len;
token->pos = 0;
grn_table_get_info(ctx, table, &table_flags, &token->encoding, NULL);
nflags |= (table_flags & GRN_OBJ_KEY_NORMALIZE);
if (!(token->nstr = grn_str_open_(ctx, GRN_TEXT_VALUE(str), GRN_TEXT_LEN(str),
nflags, token->encoding))) {
GRN_FREE(token);
ERR(GRN_TOKENIZER_ERROR, "grn_str_open failed at grn_token_open");
return NULL;
}
token->next = (unsigned char *)token->nstr->norm;
token->end = token->next + token->nstr->norm_blen;
token->len = token->nstr->length;
GRN_TEXT_INIT(&token->curr_, GRN_OBJ_DO_SHALLOW_COPY);
GRN_UINT32_INIT(&token->stat_, 0);
return NULL;
}
示例14: grn_test_table_collect_string
const GList *
grn_test_table_collect_string(grn_ctx *context,
grn_obj *table,
const gchar *text_column_name)
{
GList *records = NULL;
grn_table_cursor *cursor;
grn_id id;
grn_obj *text_column;
grn_obj value;
cursor = grn_table_cursor_open(context, table, NULL, 0, NULL, 0,
0, -1, GRN_CURSOR_ASCENDING);
grn_test_assert_context(context);
text_column = grn_obj_column(context, table,
text_column_name, strlen(text_column_name));
GRN_TEXT_INIT(&value, 0);
while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) {
GRN_BULK_REWIND(&value);
grn_obj_get_value(context, text_column, id, &value);
records = g_list_append(records, g_strndup(GRN_TEXT_VALUE(&value),
GRN_TEXT_LEN(&value)));
}
grn_obj_unlink(context, &value);
grn_obj_unlink(context, text_column);
gcut_take_list(records, g_free);
grn_test_assert(grn_table_cursor_close(context, cursor));
grn_test_assert_context(context);
return records;
}
示例15: command_schema_output_plugins
static void
command_schema_output_plugins(grn_ctx *ctx)
{
grn_obj plugin_names;
unsigned int i, n;
GRN_TEXT_INIT(&plugin_names, GRN_OBJ_VECTOR);
grn_plugin_get_names(ctx, &plugin_names);
grn_ctx_output_cstr(ctx, "plugins");
n = grn_vector_size(ctx, &plugin_names);
grn_ctx_output_map_open(ctx, "plugins", n);
for (i = 0; i < n; i++) {
const char *name;
unsigned int name_size;
name_size = grn_vector_get_element(ctx, &plugin_names, i, &name, NULL, NULL);
grn_ctx_output_str(ctx, name, name_size);
grn_ctx_output_map_open(ctx, "plugin", 1);
grn_ctx_output_cstr(ctx, "name");
grn_ctx_output_str(ctx, name, name_size);
grn_ctx_output_map_close(ctx);
}
grn_ctx_output_map_close(ctx);
GRN_OBJ_FIN(ctx, &plugin_names);
}