void cut_teardown(void) { if (context) { inverted_index_free(); if (path) grn_ii_remove(context, path); grn_ctx_fin(context); g_free(context); } /* if (vgram) grn_vgram_close(vgram); */ if (path) { g_free(path); path = NULL; } remove_tmp_directory(); record_ids_free(); expected_messages_free(); teardown_grn_logger(logger); }
void cut_setup(void) { const gchar *database_path; cut_set_fixture_data_dir(grn_test_get_base_dir(), "fixtures", "geo", NULL); remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); load_data(); points = get("Points"); short_degree_column = get("Points.short_degree"); location_index_column = get("Locations.point"); result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, points, NULL); }
void cut_setup(void) { const gchar *database_path; cut_set_fixture_data_dir(grn_test_get_base_dir(), "fixtures", "story", "taiyaki", NULL); remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); setup_values(); load_data(); shops = get("Shops"); location_index = get("Locations.shop"); result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, shops, NULL); }
void cut_setup(void) { const gchar *database_path; cut_set_fixture_data_dir(grn_test_get_base_dir(), "fixtures", "story", "taiyaki", NULL); remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL)); assert_send_command(cut_get_fixture_data_string("areas.grn", NULL)); assert_send_command(cut_get_fixture_data_string("categories.grn", NULL)); assert_send_command(cut_get_fixture_data_string("shops.grn", NULL)); assert_send_command(cut_get_fixture_data_string("synonyms.grn", NULL)); }
void cut_teardown(void) { if (cursor) { grn_obj_unlink(context, cursor); } if (result) { grn_obj_unlink(context, result); } if (column) { grn_obj_unlink(context, column); } if (table) { grn_obj_unlink(context, table); } grn_obj_close(context, database); grn_ctx_fin(context); g_free(context); remove_tmp_directory(); }
void test_expression_lifetime_over_database(void) { const gchar *path; gint i, n_tries = 100; grn_obj *expression; cut_omit("will be SEGVed."); path = cut_build_path(tmp_directory, "database.groonga", NULL); for (i = 0; i < n_tries; i++) { gint j, n_records = 100; const gchar *query; grn_obj *table, *variable; grn_obj default_column; database = grn_db_create(context, path, NULL); grn_test_assert_context(context); assert_send_command("table_create Sites 0 ShortText"); assert_send_command("column_create Sites point COLUMN_SCALAR Int32"); for (j = 0; j < n_records; j++) { gchar *command; command = g_strdup_printf("load '" "[[\"_key\", \"point\"]," "[\"http://groonga.org/version/%d\",%d]]' " "Sites", j, j); assert_send_command(command); g_free(command); } table = get_object("Sites"); GRN_EXPR_CREATE_FOR_QUERY(context, table, expression, variable); grn_obj_unlink(context, table); GRN_TEXT_INIT(&default_column, 0); GRN_TEXT_PUTS(context, &default_column, "point"); query = "point:50"; grn_expr_parse(context, expression, query, strlen(query), &default_column, GRN_OP_MATCH, GRN_OP_AND, GRN_EXPR_SYNTAX_QUERY | GRN_EXPR_ALLOW_COLUMN); grn_test_assert_context(context); grn_obj_unlink(context, &default_column); grn_expr_compile(context, expression); grn_obj_remove(context, database); database = NULL; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); } grn_ctx_fin(context); g_free(context); context = NULL; }
void cut_teardown(void) { grn_obj_close(context, database); grn_ctx_fin(context); g_free(context); remove_tmp_directory(); }
void cut_teardown(void) { teardown_database(); teardown_grn_logger(logger); remove_tmp_directory(); }
void cut_teardown(void) { if (context) { grn_ctx_fin(context); g_free(context); } remove_tmp_directory(); }
void cut_teardown(void) { if (context) { grn_obj_unlink(context, database); grn_ctx_fin(context); g_free(context); } remove_tmp_directory(); }
void cut_setup(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); ja = grn_ja_create(context, NULL, 65536, 0); vector = grn_obj_open(context, GRN_BULK, GRN_OBJ_VECTOR, GRN_DB_VOID); }
static void setup_database(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); database = grn_db_create(context, database_path, NULL); grn_test_assert_context(context); setup_ddl(); setup_data(); }
void cut_teardown(void) { if (context) { grn_ctx_fin(context); g_free(context); } teardown_grn_logger(logger); remove_tmp_directory(); }
void cut_setup(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); }
void cut_setup(void) { gchar *table_path, *vgram_path; const gchar *type_name, *table_name; cut_set_fixture_data_dir(grn_test_get_base_dir(), "fixtures", "inverted-index", NULL); logger = setup_grn_logger(); expected_messages = NULL; record_ids = NULL; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); path = g_build_filename(tmp_directory, "inverted-index", NULL); context = g_new0(grn_ctx, 1); grn_test_assert(grn_ctx_init(context, GRN_CTX_USE_QL)); GRN_CTX_SET_ENCODING(context, GRN_ENC_UTF8); db = grn_db_create(context, NULL, NULL); grn_ctx_use(context, db); type_name = "name"; type = grn_type_create(context, type_name, strlen(type_name), GRN_OBJ_KEY_VAR_SIZE, TYPE_SIZE); table_name = "lexicon"; table_path = g_build_filename(tmp_directory, "lexicon-table", NULL); lexicon = grn_table_create(context, table_name, strlen(table_name), table_path, GRN_OBJ_PERSISTENT | GRN_OBJ_TABLE_PAT_KEY, type, NULL); grn_obj_set_info(context, lexicon, GRN_INFO_DEFAULT_TOKENIZER, grn_ctx_at(context, GRN_DB_BIGRAM)); g_free(table_path); vgram_path = g_build_filename(tmp_directory, "vgram", NULL); /* vgram = grn_vgram_create(vgram_path); */ g_free(vgram_path); inverted_index = NULL; }
void cut_teardown(void) { teardown_values(); grn_obj_unlink(context, result); grn_obj_unlink(context, location_index); grn_obj_close(context, database); grn_ctx_fin(context); g_free(context); remove_tmp_directory(); }
void cut_teardown(void) { grn_obj_unlink(context, result); grn_obj_unlink(context, location_index_column); grn_obj_unlink(context, short_degree_column); grn_obj_unlink(context, points); grn_obj_close(context, database); grn_ctx_fin(context); g_free(context); remove_tmp_directory(); }
void cut_setup(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database = NULL; context2 = g_new0(grn_ctx, 1); grn_ctx_init(context2, 0); database2 = NULL; }
void cut_setup(void) { remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = NULL; logger = setup_grn_logger(); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database = grn_db_create(context, cut_build_path(tmp_directory, "table.db", NULL), NULL); }
void cut_teardown(void) { if (vector) { grn_obj_unlink(context, vector); } if (ja) { grn_ja_close(context, ja); } if (context) { grn_ctx_fin(context); g_free(context); } remove_tmp_directory(); }
void cut_setup(void) { const gchar *database_path; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); table = NULL; column = NULL; result = NULL; cursor = NULL; }
void cut_setup(void) { const gchar *database_path; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); context = g_new0(grn_ctx, 1); grn_ctx_init(context, 0); database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); assert_send_command("table_create Test TABLE_PAT_KEY ShortText"); assert_send_command("column_create Test name COLUMN_SCALAR Text"); table = get_object("Test"); }
void test_scalar_index(void) { gchar *db_path; const gchar *name; grn_obj *users, *items, *checks, *checked; grn_obj_close(context, db); remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); db_path = g_build_filename(tmp_directory, "inverted-index", NULL); db = grn_db_create(context, db_path, NULL); g_free(db_path); name = "users"; users = grn_table_create(context, name, strlen(name), NULL, GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT, NULL, 0); cut_assert_not_null(users); name = "items"; items = grn_table_create(context, name, strlen(name), NULL, GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT, NULL, 0); cut_assert_not_null(items); name = "checks"; checks = grn_column_create(context, users, name, strlen(name), NULL, GRN_OBJ_COLUMN_SCALAR|GRN_OBJ_PERSISTENT, items); cut_assert_not_null(checks); name = "checked"; checked = grn_column_create(context, items, name, strlen(name), NULL, GRN_OBJ_COLUMN_INDEX|GRN_OBJ_PERSISTENT, users); cut_assert_not_null(checked); grn_test_assert(set_index_source(checked, checks)); insert_and_search(users, items, checks, checked); grn_obj_close(context, checks); grn_obj_close(context, checked); grn_obj_close(context, items); grn_obj_close(context, users); }
void cut_setup(void) { view = NULL; entries = NULL; users = NULL; dogs = NULL; logger = setup_grn_logger(); context = g_new(grn_ctx, 1); grn_ctx_init(context, 0); remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); database = grn_db_create(context, database_path, NULL); grn_test_assert_context(context); }
void cut_teardown(void) { if (context) { if (database) { grn_obj_close(context, database); } grn_ctx_fin(context); g_free(context); } if (context2) { if (database2) { grn_obj_close(context2, database2); } grn_ctx_fin(context2); g_free(context2); } remove_tmp_directory(); }
void test_int_index(void) { gchar *db_path, *name; grn_obj *users, *items, *checks, *checked, *int_type; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory, 0700); db_path = g_build_filename(tmp_directory, "inverted-index", NULL); db = grn_db_create(context, db_path, NULL); g_free(db_path); int_type = grn_ctx_at(context, GRN_DB_INT32); cut_assert_not_null(int_type); name = "users"; users = grn_table_create(context, name, strlen(name), NULL, GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT, NULL, 0); cut_assert_not_null(users); name = "items"; items = grn_table_create(context, name, strlen(name), NULL, GRN_OBJ_TABLE_PAT_KEY|GRN_OBJ_PERSISTENT, int_type, 0); cut_assert_not_null(items); name = "checks"; checks = grn_column_create(context, users, name, strlen(name), NULL, GRN_OBJ_COLUMN_SCALAR|GRN_OBJ_PERSISTENT, items); cut_assert_not_null(checks); name = "checked"; checked = grn_column_create(context, items, name, strlen(name), NULL, GRN_OBJ_COLUMN_INDEX|GRN_OBJ_PERSISTENT, users); cut_assert_not_null(checked); grn_test_assert(set_index_source(checked, checks)); { int32_t key = 1; grn_obj value, query, *res; grn_id user1 = grn_table_add(context, users, NULL, 0, NULL); grn_id user2 = grn_table_add(context, users, NULL, 0, NULL); grn_id item = grn_table_add(context, items, &key, sizeof(int32_t), NULL); GRN_TEXT_INIT(&value, 0); GRN_TEXT_INIT(&query, 0); res = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_HASH_KEY, users, 0); cut_assert_not_null(res); grn_bulk_write(context, &value, (void *)&item, sizeof(grn_id)); value.header.domain = grn_obj_id(context, items); grn_bulk_write(context, &query, (void *)&key, sizeof(int32_t)); query.header.domain = GRN_DB_INT32; grn_test_assert(grn_obj_set_value(context, checks, user1, &value, GRN_OBJ_SET)); grn_test_assert(grn_obj_search(context, checked, &value, res, GRN_OP_OR, NULL)); cut_assert_equal_int(grn_table_size(context, res), 1); grn_test_assert(grn_obj_set_value(context, checks, user2, &value, GRN_OBJ_SET)); grn_test_assert(grn_obj_search(context, checked, &query, res, GRN_OP_OR, NULL)); cut_assert_equal_int(grn_table_size(context, res), 2); grn_obj_close(context, &query); grn_obj_close(context, &value); grn_obj_close(context, res); } grn_obj_close(context, checks); grn_obj_close(context, checked); grn_obj_close(context, items); grn_obj_close(context, users); }
void test_mroonga_index_score(void) { grn_obj *t1,*c1,*lc,*ft; grn_obj buff; grn_id r1,r2,r3,r4; remove_tmp_directory(); g_mkdir_with_parents(tmp_directory,0700); g_chdir(tmp_directory); g_mkdir_with_parents("mrn",0700); db = grn_db_create(context,"mroonga.grn",NULL); cut_assert_not_null(db); /* actual table */ t1 = grn_table_create(context,"t1",2,"mrn/t1.grn", GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT,NULL,0); cut_assert_not_null(t1); /* lexicon table */ lc = grn_table_create(context,"lc",2,"mrn/lc.grn", GRN_OBJ_TABLE_PAT_KEY|GRN_OBJ_PERSISTENT, grn_ctx_at(context, GRN_DB_SHORT_TEXT), 0); cut_assert_not_null(lc); grn_test_assert(grn_obj_set_info(context, lc, GRN_INFO_DEFAULT_TOKENIZER, grn_ctx_at(context, GRN_DB_BIGRAM))); /* actual column */ c1 = grn_column_create(context,t1,"c1",2,"mrn/t1.c1.grn", GRN_OBJ_COLUMN_SCALAR|GRN_OBJ_PERSISTENT, grn_ctx_at(context, GRN_DB_TEXT)); cut_assert_not_null(c1); /* fulltext index */ ft = grn_column_create(context,lc,"ft",2,"mrn/lc.ft.grn", GRN_OBJ_COLUMN_INDEX|GRN_OBJ_PERSISTENT,t1); cut_assert_not_null(ft); GRN_TEXT_INIT(&buff,0); /* link between actual column and fulltext index */ GRN_UINT32_SET(context, &buff, grn_obj_id(context, c1)); grn_obj_set_info(context, ft, GRN_INFO_SOURCE, &buff); /* need to use grn_id */ /* insert row */ r1 = grn_table_add(context, t1, NULL, 0, NULL); cut_assert_equal_int(1,r1); GRN_TEXT_SETS(context, &buff, "abcde"); grn_test_assert(grn_obj_set_value(context, c1, r1, &buff, GRN_OBJ_SET)); r2 = grn_table_add(context, t1, NULL, 0, NULL); cut_assert_equal_int(2,r2); GRN_TEXT_SETS(context, &buff, "fghij"); grn_test_assert(grn_obj_set_value(context, c1, r2, &buff, GRN_OBJ_SET)); r3 = grn_table_add(context, t1, NULL, 0, NULL); cut_assert_equal_int(3,r3); GRN_TEXT_SETS(context, &buff, "11 22 33"); grn_test_assert(grn_obj_set_value(context, c1, r3, &buff, GRN_OBJ_SET)); r4 = grn_table_add(context, t1, NULL, 0, NULL); cut_assert_equal_int(4,r4); GRN_TEXT_SETS(context, &buff, "44 22 55"); grn_test_assert(grn_obj_set_value(context, c1, r4, &buff, GRN_OBJ_SET)); /* confirm record are inserted in both column and index */ cut_assert_equal_int(4,grn_table_size(context,t1)); cut_assert_equal_int(23,grn_table_size(context,lc)); /* nlq search */ { grn_id id, docid; grn_obj *res; grn_table_cursor *tc; grn_obj score, *score_column; res = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, t1, 0); GRN_UINT32_INIT(&score, 0); GRN_BULK_REWIND(&buff); GRN_TEXT_SETS(context, &buff, "hij"); grn_obj_search(context, ft, &buff, res, GRN_OP_OR, NULL); cut_assert_equal_int(1, grn_table_size(context, res)); score_column = grn_obj_column(context, res, ".:score", 7); tc = grn_table_cursor_open(context, res, NULL, 0, NULL, 0, 0, 0, 0); while ((id = grn_table_cursor_next(context, tc))) { GRN_BULK_REWIND(&buff); grn_table_get_key(context, res, id, &docid, sizeof(grn_id)); cut_assert_equal_int(2, docid); cut_assert_not_null(grn_obj_get_value(context, c1, docid, &buff)); cut_assert_equal_int(5 ,GRN_TEXT_LEN(&buff)); cut_assert_equal_substring("fghij", (char*) GRN_BULK_HEAD(&buff),GRN_TEXT_LEN(&buff)); grn_obj_get_value(context, score_column, id, &score); cut_assert_equal_uint(1, GRN_UINT32_VALUE(&score)); } grn_table_cursor_close(context, tc); grn_obj_close(context, score_column); grn_obj_close(context, res); } /* boolean search */ { grn_id id, docid; grn_obj *res; grn_query *query; grn_table_cursor *tc; grn_obj score, *score_column; const char *qstr = "+22 -55"; res = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, t1, 0); GRN_UINT32_INIT(&score, 0); query = grn_query_open(context, qstr, strlen(qstr), GRN_OP_OR, 32); grn_obj_search(context, ft, (grn_obj*) query, res, GRN_OP_OR, NULL); cut_assert_equal_int(1, grn_table_size(context, res)); score_column = grn_obj_column(context, res, ".:score", 7); tc = grn_table_cursor_open(context, res, NULL, 0, NULL, 0, 0, 0, 0); while ((id = grn_table_cursor_next(context, tc))) { GRN_BULK_REWIND(&buff); grn_table_get_key(context, res, id, &docid, sizeof(grn_id)); cut_assert_equal_int(3, docid); cut_assert_not_null(grn_obj_get_value(context, c1, docid, &buff)); cut_assert_equal_int(8 ,GRN_TEXT_LEN(&buff)); cut_assert_equal_substring("11 22 33", (char*) GRN_BULK_HEAD(&buff),GRN_TEXT_LEN(&buff)); grn_obj_get_value(context, score_column, id, &score); cut_assert_equal_uint(5, GRN_UINT32_VALUE(&score)); } grn_query_close(context, query); grn_table_cursor_close(context ,tc); grn_obj_close(context, score_column); grn_obj_close(context, res); } grn_obj_close(context, &buff); grn_obj_close(context, ft); grn_obj_close(context, c1); grn_obj_close(context, lc); grn_obj_close(context, t1); }