static void
setup_data(void)
{
  assert_send_commands("load --table Sites\n"
                       "[\n"
                       "[\"_key\", \"score\", \"age\", \"description\"],\n"
                       "[\"groonga.org\", 100, 2, "
                       "\"fulltext search engine and column store\"],\n"
                       "[\"qwik.jp/senna/FrontPageJ.html\", 100, 5, "
                       "\"embeddable fulltext search engine\"],\n"
                       "[\"2ch.net\", 10, 11, \"BBS\"]\n"
                       "]");

  assert_send_commands("load --table Users\n"
                       "[\n"
                       "[\"_key\", \"name\"],\n"
                       "[\"morita\", \"Daijiro MORI\"],\n"
                       "[\"gunyara-kun\", \"Tasuku SUENAGA\"],\n"
                       "[\"yu\", \"Yutaro Shimamura\"]\n"
                       "]");

  assert_send_commands("load --table Bookmarks\n"
                       "[\n"
                       "[\"site\", \"user\", \"rank\"],\n"
                       "[\"groonga.org\", \"morita\", 100],\n"
                       "[\"groonga.org\", \"gunyara-kun\", 100],\n"
                       "[\"groonga.org\", \"yu\", 50],\n"
                       "[\"2ch.net\", \"gunyara-kun\", null],\n"
                       "[\"2ch.net\", \"yu\", 10]\n"
                       "]");
}
static void
setup_ddl(void)
{
  assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
                       "column_create Sites score COLUMN_SCALAR Int32\n"
                       "column_create Sites age COLUMN_SCALAR Int32\n"
                       "column_create Sites description COLUMN_SCALAR ShortText");

  assert_send_commands("table_create Users TABLE_PAT_KEY ShortText\n"
                       "column_create Users name COLUMN_SCALAR ShortText");

  assert_send_commands("table_create Bookmarks TABLE_NO_KEY\n"
                       "column_create Bookmarks site COLUMN_SCALAR Sites\n"
                       "column_create Bookmarks user COLUMN_SCALAR Users\n"
                       "column_create Bookmarks rank COLUMN_SCALAR Int32");

  assert_send_commands("column_create Users bookmarks COLUMN_VECTOR Bookmarks "
                       "--source Bookmarks.user");

  assert_send_commands("table_create Bigram TABLE_PAT_KEY ShortText "
                       "--default_tokenizer TokenBigram\n"
                       "column_create Bigram description "
                       "COLUMN_INDEX|WITH_POSITION Sites description");

}
static void
create_uint32_table(void)
{
  const char *table_name = "UInt32Pat";

  assert_send_commands(
    cut_take_printf("table_create %s TABLE_PAT_KEY UInt32", table_name));
  assert_send_commands(
    cut_take_printf("load --table %s\n"
                    "[\n"
                    " [\"_key\"],\n"
                    " [%u],"
                    " [%u],"
                    " [%u],"
                    " [%u],"
                    " [%u]"
                    "]",
                    table_name,
                    0x00000000U,
                    0x00000004U,
                    0x00000080U,
                    0xdeadbeefU,
                    0xffffffffU));

  table = grn_ctx_get(context, table_name, strlen(table_name));
}
static void
create_short_text_table(const GList *texts)
{
  const gchar *table_name = "ShortTextPat";
  GString *command;
  const GList *node;

  assert_send_commands(
    cut_take_printf("table_create %s TABLE_PAT_KEY ShortText", table_name));

  command = g_string_new(NULL);
  g_string_append_printf(command, "load --table %s\n", table_name);
  g_string_append(command, "[\n");
  g_string_append(command, "  [\"_key\"],\n");
  for (node = texts; node; node = g_list_next(node)) {
    const gchar *text = node->data;
    g_string_append_printf(command, "  [\"%s\"]", text);
    if (g_list_next(node)) {
      g_string_append(command, ",");
    }
    g_string_append(command, "\n");
  }
  g_string_append(command, "]");
  assert_send_commands(cut_take_string(g_string_free(command, FALSE)));

  table = grn_ctx_get(context, table_name, strlen(table_name));
}
void
test_pat_integer_index_without_query(void)
{
  assert_send_commands("table_create Ages TABLE_PAT_KEY Int32\n"
                       "column_create Ages site_index COLUMN_INDEX Sites age");
  assert_send_commands("load --table Sites\n"
                       "[\n"
                       "[\"_key\", \"score\", \"age\", \"description\"],\n"
                       "[\"mroonga.github.com\", 100, 2, "
                       "\"fast fulltext search on MySQL\"],\n"
                       "[\"groonga.rubyforge.org\", 100, 1, "
                       "\"Ruby bindings for groonga\"]\n"
                       "]");

  cut_assert_equal_string(
    "[[[5],"
      "[[\"age\",\"Int32\"],[\"_key\",\"ShortText\"]],"
       "[1,\"groonga.rubyforge.org\"],"
       "[2,\"groonga.org\"],"
       "[2,\"mroonga.github.com\"],"
       "[5,\"qwik.jp/senna/FrontPageJ.html\"],"
       "[11,\"2ch.net\"]]]",
    send_command("select Sites "
                 "--sortby \"age\" "
                 "--output_columns \"age, _key\""));
}
Beispiel #6
0
static void
create_geo_table(const gchar *load_data)
{
  const char *table_name = "Data";
  const char *column_name = "location";

  assert_send_commands(
    cut_take_printf("table_create %s TABLE_NO_KEY", table_name));
  assert_send_commands(
    cut_take_printf("column_create %s %s COLUMN_SCALAR WGS84GeoPoint",
                    table_name, column_name));
  assert_send_commands("table_create Index TABLE_PAT_KEY WGS84GeoPoint");
  assert_send_commands(
    cut_take_printf("column_create Index %s_%s COLUMN_INDEX %s %s",
                    table_name, column_name,
                    table_name, column_name));
  assert_send_commands(
    cut_take_printf("load --table %s\n"
                    "[\n"
                    " [\"%s\"],\n"
                    "%s\n"
                    "]",
                    table_name,
                    column_name,
                    load_data));

  table = grn_ctx_get(context, table_name, strlen(table_name));
  column = grn_obj_column(context, table, column_name, strlen(column_name));
}
static void
setup_ddl(void)
{
  assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
                       "column_create Sites url COLUMN_SCALAR ShortText");

  assert_send_commands("table_create Bookmarks TABLE_PAT_KEY ShortText\n"
                       "column_create Bookmarks site COLUMN_SCALAR Sites");

  assert_send_commands("column_create Sites bookmarks_site "
                       "COLUMN_INDEX Bookmarks site");
}
Beispiel #8
0
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
test_bigram_split_symbol_tokenizer(void)
{
  assert_send_commands("table_create Softwares TABLE_HASH_KEY ShortText\n"
                       "column_create Softwares comment "
                       "COLUMN_SCALAR ShortText\n"
                       "table_create Terms TABLE_PAT_KEY ShortText "
                       "--default_tokenizer TokenBigramSplitSymbol\n"
                       "column_create Terms Softwares_comment "
                       "COLUMN_INDEX|WITH_POSITION Softwares comment\n"
                       "load --table Softwares\n"
                       "[\n"
                       "[\"_key\", \"comment\"],\n"
                       "[\"groonga\", \"うむ上々な仕上がりだね。\"],\n"
                       "[\"Cutter\", \"使いやすいじゃないか。\"]\n"
                       "[\"Senna\", \"悪くないね。上々だよ。\"]\n"
                       "]");
  cut_assert_equal_string("[[[2],"
                           "[[\"_key\",\"ShortText\"]],"
                           "[\"groonga\"],"
                           "[\"Senna\"]]]",
                          send_command("select Softwares "
                                       "--output_columns '_key' "
                                       "--match_columns comment "
                                       "--query 上々"));
}
static void
create_geo_point_table(const gchar *data)
{
  const char *table_name = "GeoPointPat";

  assert_send_commands(
    cut_take_printf("table_create %s TABLE_PAT_KEY WGS84GeoPoint", table_name));
  assert_send_commands(
    cut_take_printf("load --table %s\n"
                    "[\n"
                    " [\"_key\"],\n"
                    "%s"
                    "]",
                    table_name,
                    data));

  table = grn_ctx_get(context, table_name, strlen(table_name));
}
Beispiel #11
0
void
test_tables_argument(void)
{
  const gchar *define_schema_commands =
    "table_create users TABLE_HASH_KEY Int32\n"
    "column_create users name COLUMN_SCALAR ShortText\n"
    "table_create comments TABLE_PAT_KEY ShortText\n"
    "column_create comments text COLUMN_SCALAR ShortText\n"
    "table_create sites TABLE_NO_KEY\n"
    "column_create sites url COLUMN_SCALAR ShortText\n"
    "column_create comments author COLUMN_VECTOR users";
  const gchar *load_users_commands =
    "load --table users\n"
    "[\n"
    "[\"_key\",\"name\"],\n"
    "[1000,\"ryoqun\"],\n"
    "[1001,\"hayamiz\"]\n"
    "]";
  const gchar *load_comments_commands =
    "load --table comments\n"
    "[\n"
    "[\"_key\",\"text\",\"author\"],\n"
    "[\"groonga\",\"it is fast\",[1000,1001]]\n"
    "]";
  const gchar *load_sites_commands =
    "load --table sites\n"
    "[\n"
    "[\"_id\",\"url\"],\n"
    "[1,\"http://groonga.org/\"],\n"
    "[2,\"http://qwik.jp/senna/\"]\n"
    "]";

  assert_send_commands(define_schema_commands);
  assert_send_commands(load_users_commands);
  assert_send_commands(load_comments_commands);
  assert_send_commands(load_sites_commands);
  cut_assert_equal_string(cut_take_printf("%s\n"
                                          "%s\n"
                                          "%s",
                                          define_schema_commands,
                                          load_users_commands,
                                          load_sites_commands),
                          send_command("dump --tables users,sites"));
}
Beispiel #12
0
void
test_drilldown_with_broken_reference(void)
{
  gdouble yurakucho_latitude = 35.67487;
  gdouble yurakucho_longitude = 139.76352;
  gint distance = 10 * 1000;

  assert_send_commands("delete Areas area0002");
  assert_send_commands("delete Areas area0005");
  cut_assert_equal_string(
    "[[[23],"
    "[[\"name\",\"ShortText\"],[\"_score\",\"Int32\"]],"
    "[\"たい焼き鉄次 大丸東京店\",811],"
    "[\"たいやき神田達磨 八重洲店\",972],"
    "[\"にしみや 甘味処\",1060],"
    "[\"築地 さのきや\",1187],"
    "[\"しげ田\",1537],"
    "[\"柳屋 たい焼き\",2186],"
    "[\"尾長屋 錦糸町店\",5024],"
    "[\"根津のたいやき\",5036],"
    "[\"横浜 くりこ庵 浅草店\",5106],"
    "[\"たい焼き写楽\",5464]],"
    "[[1],"
     "[[\"_key\",\"ShortText\"],"
      "[\"name\",\"ShortText\"],"
      "[\"_nsubrecs\",\"Int32\"]],"
     "[\"area0013\",\"東京都渋谷区\",1]]"
     "]",
    send_command(
      cut_take_printf(
        "select Shops "
        "--sortby '+_score, +name' "
        "--output_columns 'name, _score' "
        "--filter 'geo_in_circle(location, \"%s\", %d) && tags @ \"たいやき\"' "
        "--scorer '_score=geo_distance3(location, \"%s\")' "
        "--drilldown 'area' "
        "--drilldown_output_columns '_key, name, _nsubrecs' "
        "--drilldown_sortby '_key'",
        grn_test_location_string(yurakucho_latitude, yurakucho_longitude),
        distance,
        grn_test_location_string(yurakucho_latitude, yurakucho_longitude))));
}
static void
setup_data(void)
{
  assert_send_commands("load --table Sites\n"
                       "[\n"
                       "[\"_key\", \"url\"],\n"
                       "[\"groonga\", \"http://groonga.org\"],\n"
                       "[\"Senna\", \"http://qwik.jp/senna/FrontPageJ.html\"],\n"
                       "[\"rroonga\", \"http://groonga.rubyforge.org/\"],\n"
                       "[\"ranguba\", \"http://groonga.rubyforge.org/\"]\n"
                       "]");

  assert_send_commands("load --table Bookmarks\n"
                       "[\n"
                       "[\"_key\", \"site\"],\n"
                       "[\"search engine1\", \"Senna\"],\n"
                       "[\"search engine2\", \"groonga\"],\n"
                       "[\"groonga + Ruby\", \"rroonga\"],\n"
                       "[\"search system\", \"ranguba\"]\n"
                       "]");
}
static void
setup_data(void)
{
  assert_send_commands("table_create Sites TABLE_HASH_KEY ShortText\n"
                       "column_create Sites uri COLUMN_SCALAR ShortText\n"
                       "load --table Sites\n"
                       "[\n"
                       "[\"_key\",\"uri\"],\n"
                       "[\"groonga\",\"http://groonga.org/\"],\n"
                       "[\"razil\",\"http://razil.jp/\"]\n"
                       "]");
}
Beispiel #15
0
void
test_null(void)
{
  assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
                       "column_create Sites link COLUMN_SCALAR Sites\n"
                       "load --table Sites\n"
                       "[\n"
                       "[\"_key\"],\n"
                       "[\"groonga.org\"],\n"
                       "[\"razil.jp\"]\n"
                       "]");
  cut_assert_equal_string("[[[0],"
                          "[[\"_id\",\"UInt32\"],"
                           "[\"_key\",\"ShortText\"]]]]",
                          send_command("select Sites "
                                       "--output_columns '_id _key' "
                                       "--filter null"));
}
Beispiel #16
0
void
test_load_with_vector_int32_reference_key(void)
{
  const gchar *commands =
    "table_create users TABLE_HASH_KEY Int32\n"
    "column_create users name COLUMN_SCALAR ShortText\n"
    "table_create comments TABLE_PAT_KEY ShortText\n"
    "column_create comments text COLUMN_SCALAR ShortText\n"
    "column_create comments author COLUMN_VECTOR users\n"
    "load --table users\n"
    "[\n"
    "[\"_key\",\"name\"],\n"
    "[1000,\"ryoqun\"],\n"
    "[1001,\"hayamiz\"]\n"
    "]\n"
    "load --table comments\n"
    "[\n"
    "[\"_key\",\"author\",\"text\"],\n"
    "[\"groonga\",[1000,1001],\"it is fast\"]\n"
    "]";

  assert_send_commands(commands);
  cut_assert_equal_string(commands, send_command("dump"));
}
Beispiel #17
0
static void
load_data(void)
{
  assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
}