From null at cozmixng.org Wed Mar 3 21:20:44 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 04 Mar 2010 11:20:44 +0900 Subject: [groonga-commit:955] groonga [groonga (trunk) r1032] * normalize $(DLLIB) to work with Ruby 1.8.8. Message-ID: <20100304022044.ACDE21D1C10@mail.cozmixng.org> retro 2010-03-04 11:20:44 +0900 (Thu, 04 Mar 2010) New Revision: 1032 Log: * normalize $(DLLIB) to work with Ruby 1.8.8. Modified files: groonga/trunk/extconf.rb Modified: groonga/trunk/extconf.rb (+5 -0) =================================================================== --- groonga/trunk/extconf.rb 2010-02-17 15:29:30 +09:00 (rev 1031) +++ groonga/trunk/extconf.rb 2010-03-04 11:20:44 +09:00 (rev 1032) @@ -167,6 +167,7 @@ File.open("Makefile", "w") do |f| objs = [] co = nil + dllib = nil makefile.each_line do |line| case line when /^DLLIB\s*=\s*/ @@ -195,6 +196,10 @@ co = line f.puts(line) else + if dllib + line = line.gsub(/\$\(RUBYARCHDIR\)\/\$\(DLLIB\)/, + "$(RUBYARCHDIR)/#{dllib.chomp}") + end f.puts(line) end end From null at cozmixng.org Wed Mar 3 22:20:29 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 04 Mar 2010 12:20:29 +0900 Subject: [groonga-commit:956] groonga [groonga (trunk) r1034] * add m_seki to thanks list. Message-ID: <20100304032029.D07A41D1C13@mail.cozmixng.org> retro 2010-03-04 12:20:29 +0900 (Thu, 04 Mar 2010) New Revision: 1034 Log: * add m_seki to thanks list. Thanks!!! Modified files: groonga/trunk/README.ja.rdoc groonga/trunk/README.rdoc Modified: groonga/trunk/README.ja.rdoc (+1 -0) =================================================================== --- groonga/trunk/README.ja.rdoc 2010-03-04 11:18:22 +09:00 (rev 1033) +++ groonga/trunk/README.ja.rdoc 2010-03-04 12:20:29 +09:00 (rev 1034) @@ -62,3 +62,4 @@ * ???????????? * id:mat_aki??: ???????????????????? * @yune_kotomi: ?????????????? +* ???: ?????????????? Modified: groonga/trunk/README.rdoc (+1 -0) =================================================================== --- groonga/trunk/README.rdoc 2010-03-04 11:18:22 +09:00 (rev 1033) +++ groonga/trunk/README.rdoc 2010-03-04 12:20:29 +09:00 (rev 1034) @@ -63,3 +63,4 @@ * fixed bugs. * id:mat_aki: sent bug reports. * @yune_kotomi: sent a bug report. +* m_seki: sent bug reports. From null at cozmixng.org Wed Mar 3 22:20:31 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 04 Mar 2010 12:20:31 +0900 Subject: [groonga-commit:957] groonga [groonga (trunk) r1035] * fix SEGV on GC. Message-ID: <20100304032031.AAA241D1C15@mail.cozmixng.org> retro 2010-03-04 12:20:31 +0900 (Thu, 04 Mar 2010) New Revision: 1035 Log: * fix SEGV on GC. Modified files: groonga/trunk/ext/rb-grn-context.c groonga/trunk/ext/rb-grn-database.c groonga/trunk/ext/rb-grn-object.c Modified: groonga/trunk/ext/rb-grn-object.c (+9 -4) =================================================================== --- groonga/trunk/ext/rb-grn-object.c 2010-03-04 11:20:01 +09:00 (rev 1034) +++ groonga/trunk/ext/rb-grn-object.c 2010-03-04 12:20:31 +09:00 (rev 1035) @@ -158,11 +158,16 @@ grn_object = rb_grn_object->object; debug("rb-free: %p:%p:%p\n", context, grn_object, rb_grn_object); if (!rb_grn_exited && context && grn_object) { - rb_grn_object->context = NULL; - rb_grn_object->object = NULL; - debug("type: %x; need_close: %d\n", + grn_user_data *user_data; + + user_data = grn_obj_user_data(context, grn_object); + debug("type: %x; need_close: %d; user_data: %p\n", grn_object->header.type, - rb_grn_object->need_close); + rb_grn_object->need_close, + user_data); + if (user_data && user_data->ptr) { + rb_grn_object_finalizer(context, 1, &grn_object, user_data); + } if (rb_grn_object->need_close) { grn_obj_unlink(context, grn_object); } Modified: groonga/trunk/ext/rb-grn-context.c (+1 -1) =================================================================== --- groonga/trunk/ext/rb-grn-context.c 2010-03-04 11:20:01 +09:00 (rev 1034) +++ groonga/trunk/ext/rb-grn-context.c 2010-03-04 12:20:31 +09:00 (rev 1035) @@ -67,7 +67,7 @@ database = grn_ctx_db(context); debug("context:database: %p:%p\n", context, database); if (database && database->header.type == GRN_DB) { - grn_obj_close(context, database); + grn_obj_unlink(context, database); } grn_ctx_fin(context); } Modified: groonga/trunk/ext/rb-grn-database.c (+2 -2) =================================================================== --- groonga/trunk/ext/rb-grn-database.c 2010-03-04 11:20:01 +09:00 (rev 1034) +++ groonga/trunk/ext/rb-grn-database.c 2010-03-04 12:20:31 +09:00 (rev 1035) @@ -137,7 +137,7 @@ old_database = grn_ctx_db(context); if (old_database) - grn_obj_close(context, old_database); + grn_obj_unlink(context, old_database); database = grn_db_create(context, path, &create_args); rb_grn_context_check(context, rb_ary_new4(argc, argv)); rb_database = GRNOBJECT2RVAL(klass, context, database, RB_GRN_TRUE); @@ -188,7 +188,7 @@ old_database = grn_ctx_db(context); if (old_database) - grn_obj_close(context, old_database); + grn_obj_unlink(context, old_database); database = grn_db_open(context, path); rb_grn_object_assign(Qnil, self, rb_context, context, database); rb_grn_context_check(context, self); From null at cozmixng.org Fri Mar 12 08:50:36 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 12 Mar 2010 22:50:36 +0900 Subject: [groonga-commit:958] groonga [groonga (trunk) r1039] * mark Ruby objects in database. Message-ID: <20100312135036.31E971D1C10@mail.cozmixng.org> retro 2010-03-12 22:50:35 +0900 (Fri, 12 Mar 2010) New Revision: 1039 Log: * mark Ruby objects in database. Modified files: groonga/trunk/ext/rb-grn-database.c Modified: groonga/trunk/ext/rb-grn-database.c (+57 -0) =================================================================== --- groonga/trunk/ext/rb-grn-database.c 2010-03-09 10:05:07 +09:00 (rev 1038) +++ groonga/trunk/ext/rb-grn-database.c 2010-03-12 22:50:35 +09:00 (rev 1039) @@ -51,6 +51,61 @@ } static void +rb_grn_database_mark_existing_ruby_object (grn_ctx *context, grn_obj *database) +{ + grn_table_cursor *cursor; + grn_id id; + + cursor = grn_table_cursor_open(context, database, NULL, 0, NULL, 0, + 0, -1, GRN_CURSOR_ASCENDING); + if (!cursor) + return; + + while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) { + grn_obj *object; + grn_user_data *user_data; + RbGrnObject *rb_grn_object; + + object = grn_ctx_at(context, id); + if (!object) + continue; + user_data = grn_obj_user_data(context, object); + if (!user_data) + continue; + rb_grn_object = RB_GRN_OBJECT(user_data->ptr); + if (!rb_grn_object) + continue; + rb_gc_mark(rb_grn_object->self); + } + grn_table_cursor_close(context, cursor); +} + +static void +rb_grn_database_mark (void *data) +{ + RbGrnObject *rb_grn_database = data; + grn_ctx *context; + grn_obj *database; + + if (!rb_grn_database) + return; + + context = rb_grn_database->context; + database = rb_grn_database->object; + if (!context || !database) + return; + + rb_grn_database_mark_existing_ruby_object(context, database); +} + +static VALUE +rb_grn_database_alloc (VALUE klass) +{ + return Data_Wrap_Struct(klass, rb_grn_database_mark, rb_grn_object_free, + NULL); +} + +static void rb_grn_database_deconstruct (RbGrnObject *rb_grn_database, grn_obj **database, grn_ctx **context, @@ -390,6 +445,8 @@ rb_grn_init_database (VALUE mGrn) { rb_cGrnDatabase = rb_define_class_under(mGrn, "Database", rb_cGrnObject); + rb_define_alloc_func(rb_cGrnDatabase, rb_grn_database_alloc); + rb_include_module(rb_cGrnDatabase, rb_mEnumerable); rb_include_module(rb_cGrnDatabase, rb_mGrnEncodingSupport); From null at cozmixng.org Fri Mar 12 08:50:34 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 12 Mar 2010 22:50:34 +0900 Subject: [groonga-commit:959] groonga [groonga (trunk) r1038] * follow the recent groonga name restrictions: don't use '-' Message-ID: <20100312135034.9BCA11D1C0D@mail.cozmixng.org> retro 2010-03-12 22:50:34 +0900 (Fri, 12 Mar 2010) New Revision: 1038 Log: * follow the recent groonga name restrictions: don't use '-' in column, table and type name. Modified files: groonga/trunk/ext/rb-grn-table.c groonga/trunk/test/test-column.rb groonga/trunk/test/test-expression-builder.rb groonga/trunk/test/test-schema.rb groonga/trunk/test/test-table.rb groonga/trunk/test/test-type.rb Modified: groonga/trunk/test/test-schema.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-schema.rb 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/test/test-schema.rb 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -288,7 +288,7 @@ def test_index_with_full_option path = @tmp_dir + "index-column.groonga" assert_nil(context["Terms.content"]) - index_column_name = "Posts-index" + index_column_name = "Posts_index" Groonga::Schema.create_table("Posts") do |table| table.long_text :content Modified: groonga/trunk/test/test-expression-builder.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-expression-builder.rb 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/test/test-expression-builder.rb 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -27,7 +27,7 @@ @terms = Groonga::PatriciaTrie.create(:name => "Terms", :default_tokenizer => "TokenBigram") - @terms.define_index_column("user-name", @users, :source => @name) + @terms.define_index_column("user_name", @users, :source => @name) @bookmarks = Groonga::Array.create(:name => "Bookmarks") @bookmarks.define_column("user", @users) Modified: groonga/trunk/ext/rb-grn-table.c (+8 -2) =================================================================== --- groonga/trunk/ext/rb-grn-table.c 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/ext/rb-grn-table.c 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -429,7 +429,10 @@ column = grn_column_create(context, table, name, name_size, path, flags, value_type); - rb_grn_context_check(context, self); + if (context->rc) { + rb_grn_context_check(context, + rb_ary_new3(2, self, rb_ary_new4(argc, argv))); + } rb_column = GRNCOLUMN2RVAL(Qnil, context, column, RB_GRN_TRUE); rb_ary_push(columns, rb_column); @@ -553,7 +556,10 @@ column = grn_column_create(context, table, name, name_size, path, flags, value_type); - rb_grn_context_check(context, self); + if (context->rc) { + rb_grn_context_check(context, + rb_ary_new3(2, self, rb_ary_new4(argc, argv))); + } rb_column = GRNCOLUMN2RVAL(Qnil, context, column, RB_GRN_TRUE); if (!NIL_P(rb_source)) Modified: groonga/trunk/test/test-type.rb (+12 -2) =================================================================== --- groonga/trunk/test/test-type.rb 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/test/test-type.rb 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -19,10 +19,20 @@ setup :setup_database def test_new - type = Groonga::Type.new("user-id", :type => :integer) - assert_equal("user-id", type.name) + type = Groonga::Type.new("user_id", :type => :integer) + assert_equal("user_id", type.name) end + def test_new_with_hyphen_name + exception = assert_raise(Groonga::InvalidArgument) do + Groonga::Type.new("user-id", :type => :integer) + end + message = + "name can't start with '_' and 0-9, and contains only 0-9, A-Z, a-z, or _" + assert_match(/#{Regexp.escape(message)}/, + exception.message) + end + def test_builtins assert_equal_type("Object", Groonga::Type::OBJECT) # FIXME!!! assert_equal_type("Bool", Groonga::Type::BOOLEAN) Modified: groonga/trunk/test/test-table.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-table.rb 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/test/test-table.rb 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -190,7 +190,7 @@ bookmarks.define_column("content", "Text") terms = Groonga::Hash.create(:name => "Terms") terms.default_tokenizer = "TokenBigram" - index = terms.define_index_column("content-index", bookmarks, + index = terms.define_index_column("content_index", bookmarks, :with_section => true, :source => "Bookmarks.content") bookmarks.add("google", :content => "Search engine") Modified: groonga/trunk/test/test-column.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-column.rb 2010-03-04 15:07:46 +09:00 (rev 1037) +++ groonga/trunk/test/test-column.rb 2010-03-12 22:50:34 +09:00 (rev 1038) @@ -59,7 +59,7 @@ def setup_indexes @bookmarks_index_path = @tables_dir + "bookmarks-index" @bookmarks_index = - Groonga::PatriciaTrie.create(:name => "bookmarks-index", + Groonga::PatriciaTrie.create(:name => "BookmarksIndex", :path => @bookmarks_index_path.to_s, :key_type => "ShortText") @bookmarks_index.default_tokenizer = "TokenBigram" From null at cozmixng.org Fri Mar 12 08:50:39 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 12 Mar 2010 22:50:39 +0900 Subject: [groonga-commit:960] groonga [groonga (trunk) r1041] * follow the current groonga changes. Message-ID: <20100312135039.393351D1C16@mail.cozmixng.org> retro 2010-03-12 22:50:38 +0900 (Fri, 12 Mar 2010) New Revision: 1041 Log: * follow the current groonga changes. Modified files: groonga/trunk/test/test-column.rb groonga/trunk/test/test-expression-builder.rb groonga/trunk/test/test-table-select-normalize.rb groonga/trunk/test/test-table-select.rb Modified: groonga/trunk/test/test-expression-builder.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-expression-builder.rb 2010-03-10 12:06:31 +09:00 (rev 1040) +++ groonga/trunk/test/test-expression-builder.rb 2010-03-12 22:50:38 +09:00 (rev 1041) @@ -115,7 +115,7 @@ end def test_query_string - result = @users.select("name:%ro") + result = @users.select("name:@ro") assert_equal(["morita", "yu"], result.collect {|record| record.key.key}) end Modified: groonga/trunk/test/test-table-select.rb (+4 -4) =================================================================== --- groonga/trunk/test/test-table-select.rb 2010-03-10 12:06:31 +09:00 (rev 1040) +++ groonga/trunk/test/test-table-select.rb 2010-03-12 22:50:38 +09:00 (rev 1041) @@ -57,7 +57,7 @@ end def test_select_query - result = @comments.select("content:%Hello") + result = @comments.select("content:@Hello") assert_equal_select_result([@comment1, @comment2], result) end @@ -83,14 +83,14 @@ end def test_select_query_with_block - result = @comments.select("content:%Hello") do |record| + result = @comments.select("content:@Hello") do |record| record["created_at"] < Time.parse("2009-08-01") end assert_equal_select_result([@comment2], result) end def test_select_query_with_block_match - result = @comments.select("content:%Hello") do |record| + result = @comments.select("content:@Hello") do |record| record.match("World", "content") end assert_equal_select_result([@comment2], result) @@ -103,7 +103,7 @@ end def test_select_query_japanese - result = @comments.select("content:%??TV") + result = @comments.select("content:@??TV") assert_equal_select_result([@japanese_comment], result) end Modified: groonga/trunk/test/test-table-select-normalize.rb (+2 -2) =================================================================== --- groonga/trunk/test/test-table-select-normalize.rb 2010-03-10 12:06:31 +09:00 (rev 1040) +++ groonga/trunk/test/test-table-select-normalize.rb 2010-03-12 22:50:38 +09:00 (rev 1041) @@ -37,12 +37,12 @@ end def test_select_query_with_japanese - result = @comments.select("content:%??TV") + result = @comments.select("content:@??TV") assert_equal_select_result([@japanese_comment], result) end def test_select_query_only_in_japanese - result = @comments.select("content:%???") + result = @comments.select("content:@???") assert_equal_select_result([@japanese_comment], result) end end Modified: groonga/trunk/test/test-column.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-column.rb 2010-03-10 12:06:31 +09:00 (rev 1040) +++ groonga/trunk/test/test-column.rb 2010-03-12 22:50:38 +09:00 (rev 1041) @@ -225,7 +225,7 @@ expression = Groonga::Expression.new variable = expression.define_variable(:domain => @posts) expression.append_object(variable) - expression.parse("body:%drive", :syntax => :query) + expression.parse("body:@drive", :syntax => :query) expression.compile result = @body.select(expression) assert_equal(["Drive and Eat"], From null at cozmixng.org Fri Mar 12 08:50:40 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 12 Mar 2010 22:50:40 +0900 Subject: [groonga-commit:961] groonga [groonga (trunk) r1042] * follow the current groonga changes. Message-ID: <20100312135040.B0E1D1D1C17@mail.cozmixng.org> retro 2010-03-12 22:50:40 +0900 (Fri, 12 Mar 2010) New Revision: 1042 Log: * follow the current groonga changes. Modified files: groonga/trunk/test/test-table-select.rb Modified: groonga/trunk/test/test-table-select.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-table-select.rb 2010-03-12 14:25:56 +09:00 (rev 1041) +++ groonga/trunk/test/test-table-select.rb 2010-03-12 22:50:40 +09:00 (rev 1042) @@ -75,7 +75,7 @@ expression = Groonga::Expression.new variable = expression.define_variable(:domain => @comments) expression.append_object(variable) - expression.parse("content:%Hello", :syntax => :query) + expression.parse("content:@Hello", :syntax => :query) expression.compile result = @comments.select(expression) assert_equal(expression, result.expression) From null at cozmixng.org Fri Mar 12 08:50:37 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 12 Mar 2010 22:50:37 +0900 Subject: [groonga-commit:962] groonga [groonga (trunk) r1040] * fix GC crash!!! (I hope so!!!) Message-ID: <20100312135037.BC1461D1C14@mail.cozmixng.org> retro 2010-03-12 22:50:37 +0900 (Fri, 12 Mar 2010) New Revision: 1040 Log: * fix GC crash!!! (I hope so!!!) Modified files: groonga/trunk/ext/rb-grn-object.c groonga/trunk/ext/rb-grn.h Modified: groonga/trunk/ext/rb-grn-object.c (+19 -18) =================================================================== --- groonga/trunk/ext/rb-grn-object.c 2010-03-09 14:08:58 +09:00 (rev 1039) +++ groonga/trunk/ext/rb-grn-object.c 2010-03-12 22:50:37 +09:00 (rev 1040) @@ -156,15 +156,17 @@ context = rb_grn_object->context; grn_object = rb_grn_object->object; - debug("rb-free: %p:%p:%p\n", context, grn_object, rb_grn_object); - if (!rb_grn_exited && context && grn_object) { + debug("rb-free: %p:%p:%p; %d\n", context, grn_object, rb_grn_object, + rb_grn_object->have_finalizer); + if (!rb_grn_exited && context && grn_object && rb_grn_object->have_finalizer) { grn_user_data *user_data; user_data = grn_obj_user_data(context, grn_object); - debug("type: %x; need_close: %d; user_data: %p\n", + debug("type: %x; need_close: %d; user_data: %p; ptr: %p\n", grn_object->header.type, rb_grn_object->need_close, - user_data); + user_data, + user_data ? user_data->ptr : NULL); if (user_data && user_data->ptr) { rb_grn_object_finalizer(context, 1, &grn_object, user_data); } @@ -272,26 +274,25 @@ RbGrnObject *rb_grn_object, grn_ctx *context, grn_obj *object) { + grn_user_data *user_data; + rb_grn_object->context = context; rb_grn_object->object = object; rb_grn_object->self = self; rb_grn_object->need_close = RB_GRN_TRUE; + rb_grn_object->have_finalizer = RB_GRN_FALSE; + user_data = grn_obj_user_data(context, object); + if (user_data) { + debug("set-finalizer: %p:%p:%p 0x%x\n", + context, object, rb_grn_object, + object->header.type); + user_data->ptr = rb_grn_object; + grn_obj_set_finalizer(context, object, rb_grn_object_finalizer); + rb_grn_object->have_finalizer = RB_GRN_TRUE; + } + switch (object->header.type) { - case GRN_DB: - case GRN_CURSOR_TABLE_HASH_KEY: - case GRN_CURSOR_TABLE_PAT_KEY: - case GRN_CURSOR_TABLE_NO_KEY: - case GRN_TABLE_HASH_KEY: - case GRN_TABLE_PAT_KEY: - case GRN_TABLE_NO_KEY: - case GRN_COLUMN_FIX_SIZE: - case GRN_COLUMN_VAR_SIZE: - case GRN_COLUMN_INDEX: - case GRN_EXPR: - grn_obj_user_data(context, object)->ptr = rb_grn_object; - grn_obj_set_finalizer(context, object, rb_grn_object_finalizer); - break; case GRN_PROC: case GRN_TYPE: rb_grn_object->need_close = RB_GRN_FALSE; Modified: groonga/trunk/ext/rb-grn.h (+1 -0) =================================================================== --- groonga/trunk/ext/rb-grn.h 2010-03-09 14:08:58 +09:00 (rev 1039) +++ groonga/trunk/ext/rb-grn.h 2010-03-12 22:50:37 +09:00 (rev 1040) @@ -110,6 +110,7 @@ grn_obj *range; grn_id range_id; rb_grn_boolean need_close; + rb_grn_boolean have_finalizer; }; typedef struct _RbGrnNamedObject RbGrnNamedObject; From null at cozmixng.org Wed Mar 17 01:20:29 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Wed, 17 Mar 2010 14:20:29 +0900 Subject: [groonga-commit:963] groonga [groonga (trunk) r1044] * add Context#select. Message-ID: <20100317052029.6A7CA1D1C0F@mail.cozmixng.org> retro 2010-03-17 14:20:28 +0900 (Wed, 17 Mar 2010) New Revision: 1044 Log: * add Context#select. Added files: groonga/trunk/lib/groonga/context.rb groonga/trunk/test/test-context-select.rb Modified files: groonga/trunk/lib/groonga.rb Modified: groonga/trunk/lib/groonga.rb (+1 -0) =================================================================== --- groonga/trunk/lib/groonga.rb 2010-03-17 12:40:56 +09:00 (rev 1043) +++ groonga/trunk/lib/groonga.rb 2010-03-17 14:20:28 +09:00 (rev 1044) @@ -79,5 +79,6 @@ end end +require 'groonga/context' require 'groonga/patricia-trie' require 'groonga/schema' Added: groonga/trunk/lib/groonga/context.rb (+147 -0) =================================================================== --- groonga/trunk/lib/groonga/context.rb 2010-03-17 12:40:56 +09:00 (rev 1043) +++ groonga/trunk/lib/groonga/context.rb 2010-03-17 14:20:28 +09:00 (rev 1044) @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2010 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +module Groonga + class Context + # call-seq: + # context.select(table, options={}) -> SelectResult + # + # _table_??????????????????????? + # ???_table_???????????????????? + # ??? + # + # _options_??????????????? + # + # [_output_columns_] ??????????????? + # [_XXX_] TODO + # + # ?: + # TODO + def select(table, options={}) + select = SelectCommand.new(self, table, options) + select.exec + end + + class SelectResult < Struct.new(:code, :start_time, :elapsed, + :n_hits, :columns, :values, + :drill_down) + class << self + def parse(json) + status, (select_result, drill_down_results) = parse_json(json) + result = new + code, start_time, elapsed = status + result.code = code + result.start_time = Time.at(start_time) + result.elapsed = elapsed + n_hits, columns, values = extract_result(select_result) + result.n_hits = n_hits + result.columns = columns + result.values = values + if drill_down_results + result.drill_down = parse_drill_down_results(drill_down_results) + end + result + end + + def create_records(columns, values) + records = [] + values.each do |value| + record = {} + columns.each_with_index do |(name, type), i| + record[name] = value[i] + end + records << record + end + records + end + + private + def parse_drill_down_results(results) + results.collect do |result| + n_hits, columns, values = extract_result(drill_down) + drill_down_result = DrillDownResult.new + drill_down_result.n_hits = n_hits + drill_down_result.columns = columns + drill_down_result.values = values + drill_down_result + end + end + + def extract_result(result) + meta_data, columns, *values = result + n_hits, = meta_data + [n_hits, columns, values] + end + + begin + require 'json' + def parse_json(json) + JSON.parse(json) + end + rescue LoadError + require 'yaml' + def parse_json(json) + YAML.load(json) + end + end + end + + def records + @records ||= self.class.create_records(columns, values) + end + + class DrillDownResult < Struct.new(:n_hits, :columns, :values) + def records + @records ||= SelectResult.create_records(columns, values) + end + end + end + + class SelectCommand + def initialize(context, table, options) + @context = context + @table = table + @options = options + end + + def exec + request_id = @context.send(query) + loop do + response_id, result = @context.receive + return SelectResult.parse(result) if request_id == response_id + # raise if request_id < response_id + end + end + + private + def query + if @table.is_a?(String) + table_name = @table + else + table_name = @table.name + end + _query = "select #{table_name}" + @options.each do |key, value| + value = value.join(", ") if value.is_a?(::Array) + escaped_value = value.gsub(/"/, '\\"') + _query << " --#{key} \"#{escaped_value}\"" + end + _query + end + end + end +end Added: groonga/trunk/test/test-context-select.rb (+45 -0) =================================================================== --- groonga/trunk/test/test-context-select.rb 2010-03-17 12:40:56 +09:00 (rev 1043) +++ groonga/trunk/test/test-context-select.rb 2010-03-17 14:20:28 +09:00 (rev 1044) @@ -0,0 +1,45 @@ +# Copyright (C) 2010 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +class ContextSelectTest < Test::Unit::TestCase + include GroongaTestUtils + + setup :setup_database + setup + def setup_data + @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText") + @users.add("morita") + @users.add("gunyara-kun") + @users.add("yu") + end + + def test_no_option + result = context.select(@users) + assert_equal([3, + [{"_id" => 1, "_key" => "morita"}, + {"_id" => 2, "_key" => "gunyara-kun"}, + {"_id" => 3, "_key" => "yu"}]], + [result.n_hits, result.records]) + end + + def test_output_columns + result = context.select(@users, :output_columns => ["_key"]) + assert_equal([3, + [{"_key" => "morita"}, + {"_key" => "gunyara-kun"}, + {"_key" => "yu"}]], + [result.n_hits, result.records]) + end +end From null at cozmixng.org Thu Mar 18 03:50:55 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 18 Mar 2010 16:50:55 +0900 Subject: [groonga-commit:964] groonga [groonga (trunk) r1046] * support drill down mapping. Message-ID: <20100318075055.536D51D1C0B@mail.cozmixng.org> retro 2010-03-18 16:50:54 +0900 (Thu, 18 Mar 2010) New Revision: 1046 Log: * support drill down mapping. Modified files: groonga/trunk/lib/groonga/context.rb groonga/trunk/test/test-context-select.rb Modified: groonga/trunk/lib/groonga/context.rb (+27 -9) =================================================================== --- groonga/trunk/lib/groonga/context.rb 2010-03-18 14:42:46 +09:00 (rev 1045) +++ groonga/trunk/lib/groonga/context.rb 2010-03-18 16:50:54 +09:00 (rev 1046) @@ -41,8 +41,8 @@ :n_hits, :columns, :values, :drill_down) class << self - def parse(json) - status, (select_result, drill_down_results) = parse_json(json) + def parse(json, drill_down_keys) + status, (select_result, *drill_down_results) = parse_json(json) result = new return_code, start_time, elapsed, error_message = status result.return_code = return_code @@ -54,7 +54,8 @@ result.columns = columns result.values = values if drill_down_results - result.drill_down = parse_drill_down_results(drill_down_results) + result.drill_down = parse_drill_down_results(drill_down_results, + drill_down_keys) end result end @@ -72,15 +73,17 @@ end private - def parse_drill_down_results(results) - results.collect do |result| + def parse_drill_down_results(results, keys) + named_results = {} + results.each_with_index do |drill_down, i| n_hits, columns, values = extract_result(drill_down) drill_down_result = DrillDownResult.new drill_down_result.n_hits = n_hits drill_down_result.columns = columns drill_down_result.values = values - drill_down_result + named_results[keys[i]] = drill_down_result end + named_results end def extract_result(result) @@ -121,19 +124,34 @@ def initialize(context, table, options) @context = context @table = table - @options = options + @options = normalize_options(options) end def exec request_id = @context.send(query) loop do response_id, result = @context.receive - return SelectResult.parse(result) if request_id == response_id + if request_id == response_id + drill_down_keys = @options["drilldown"] + if drill_down_keys.is_a?(String) + drill_down_keys = drill_down_keys.split(/(?:\s+|\s*,\s*)/) + end + return SelectResult.parse(result, drill_down_keys) + end # raise if request_id < response_id end end private + def normalize_options(options) + normalized_options = {} + options.each do |key, value| + key = key.to_s.gsub(/-/, "_").gsub(/drill_down/, "drilldown") + normalized_options[key] = value + end + normalized_options + end + def query if @table.is_a?(String) table_name = @table @@ -143,7 +161,7 @@ _query = "select #{table_name}" @options.each do |key, value| value = value.join(", ") if value.is_a?(::Array) - escaped_value = value.gsub(/"/, '\\"') + escaped_value = value.to_s.gsub(/"/, '\\"') _query << " --#{key} \"#{escaped_value}\"" end _query Modified: groonga/trunk/test/test-context-select.rb (+34 -5) =================================================================== --- groonga/trunk/test/test-context-select.rb 2010-03-18 14:42:46 +09:00 (rev 1045) +++ groonga/trunk/test/test-context-select.rb 2010-03-18 16:50:54 +09:00 (rev 1046) @@ -20,17 +20,22 @@ setup def setup_data @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText") - @users.add("morita") - @users.add("gunyara-kun") + @books = Groonga::Hash.create(:name => "Books", :key_type => "ShortText") + @users.define_column("book", "Books") + @users.add("morita", :book => "the groonga book") + @users.add("gunyara-kun", :book => "the groonga book") @users.add("yu") end def test_no_option result = context.select(@users) assert_equal([3, - [{"_id" => 1, "_key" => "morita"}, - {"_id" => 2, "_key" => "gunyara-kun"}, - {"_id" => 3, "_key" => "yu"}]], + [{"_id" => 1, "_key" => "morita", + "book" => "the groonga book"}, + {"_id" => 2, "_key" => "gunyara-kun", + "book" => "the groonga book"}, + {"_id" => 3, "_key" => "yu", + "book" => ""}]], [result.n_hits, result.records]) end @@ -48,4 +53,28 @@ {"_key" => "yu"}]], [result.n_hits, result.records]) end + + def test_drill_down + result = context.select(@users, + :output_columns => ["_key"], + :drill_down => ["_key", "book"], + :drill_down_output_columns => "_key", + :drill_down_limit => 10) + normalized_drill_down = {} + result.drill_down.each do |key, drill_down| + normalized_drill_down[key] = [drill_down.n_hits, drill_down.records] + end + assert_equal([3, + [{"_key" => "morita"}, + {"_key" => "gunyara-kun"}, + {"_key" => "yu"}], + { + "_key" => [3, [{"_key" => "morita"}, + {"_key" => "gunyara-kun"}, + {"_key" => "yu"}]], + "book" => [1, [{"_key" => "the groonga book"}]], + }, + ], + [result.n_hits, result.records, normalized_drill_down]) + end end From null at cozmixng.org Sun Mar 21 10:05:28 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Sun, 21 Mar 2010 23:05:28 +0900 Subject: [groonga-commit:965] groonga [groonga (trunk) r1047] add a test for search with normalization Message-ID: <20100321140528.9097F1D1C0B@mail.cozmixng.org> retro 2010-03-21 23:05:27 +0900 (Sun, 21 Mar 2010) New Revision: 1047 Log: add a test for search with normalization Modified files: groonga/trunk/test/test-table-select-normalize.rb Modified: groonga/trunk/test/test-table-select-normalize.rb (+6 -1) =================================================================== --- groonga/trunk/test/test-table-select-normalize.rb 2010-03-18 16:46:53 +09:00 (rev 1046) +++ groonga/trunk/test/test-table-select-normalize.rb 2010-03-21 23:05:27 +09:00 (rev 1047) @@ -32,7 +32,7 @@ :with_section => true, :source => "Comments.content") @japanese_comment = - @comments.add(:content => "?????TV???????", + @comments.add(:content => "?????TV?????...????????", :created_at => Time.parse("2009-06-09")) end @@ -41,6 +41,11 @@ assert_equal_select_result([@japanese_comment], result) end + def test_select_query_with_japanese_parenthesis + result = @comments.select("content:@??") + assert_equal_select_result([@japanese_comment], result) + end + def test_select_query_only_in_japanese result = @comments.select("content:@???") assert_equal_select_result([@japanese_comment], result) From null at cozmixng.org Wed Mar 24 10:50:30 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Wed, 24 Mar 2010 23:50:30 +0900 Subject: [groonga-commit:966] groonga [groonga (trunk) r1048] * add Table#have_column?. Message-ID: <20100324145030.CBF9F1D1C28@mail.cozmixng.org> retro 2010-03-24 23:50:30 +0900 (Wed, 24 Mar 2010) New Revision: 1048 Log: * add Table#have_column?. Modified files: groonga/trunk/ext/rb-grn-table.c groonga/trunk/test/test-table.rb Modified: groonga/trunk/ext/rb-grn-table.c (+57 -16) =================================================================== --- groonga/trunk/ext/rb-grn-table.c 2010-03-21 22:56:43 +09:00 (rev 1047) +++ groonga/trunk/ext/rb-grn-table.c 2010-03-24 23:50:30 +09:00 (rev 1048) @@ -618,6 +618,27 @@ return rb_column; } +static void +ruby_object_to_column_name (VALUE rb_name, + const char **name, unsigned *name_size) +{ + switch (TYPE(rb_name)) { + case T_SYMBOL: + *name = rb_id2name(SYM2ID(rb_name)); + *name_size = strlen(*name); + break; + case T_STRING: + *name = StringValuePtr(rb_name); + *name_size = RSTRING_LEN(rb_name); + break; + default: + rb_raise(rb_eArgError, + "column name should be String or Symbol: %s", + rb_grn_inspect(rb_name)); + break; + } +} + /* * call-seq: * table.column(name) -> Groonga::Column or nil @@ -645,22 +666,7 @@ NULL, NULL, NULL, &columns); - switch (TYPE(rb_name)) { - case T_SYMBOL: - name = rb_id2name(SYM2ID(rb_name)); - name_size = strlen(name); - break; - case T_STRING: - name = StringValuePtr(rb_name); - name_size = RSTRING_LEN(rb_name); - break; - default: - rb_raise(rb_eArgError, - "column name should be String or Symbol: %s", - rb_grn_inspect(rb_name)); - break; - } - + ruby_object_to_column_name(rb_name, &name, &name_size); raw_columns = RARRAY_PTR(columns); n = RARRAY_LEN(columns); for (i = 0; i < n; i++) { @@ -779,6 +785,39 @@ return rb_columns; } +/* + * call-seq: + * table.have_column?(name) -> true/false + * + * ?????_name_????????????+true+???? + */ +static VALUE +rb_grn_table_have_column (VALUE self, VALUE rb_name) +{ + grn_ctx *context = NULL; + grn_obj *table; + grn_obj *column; + const char *name = NULL; + unsigned name_size = 0; + VALUE result = Qfalse; + + rb_grn_table_deconstruct(SELF(self), &table, &context, + NULL, NULL, + NULL, NULL, NULL, + NULL); + + ruby_object_to_column_name(rb_name, &name, &name_size); + column = grn_obj_column(context, table, name, name_size); + if (!column) + return Qfalse; + + if (column->header.type != GRN_ACCESSOR) + result = Qtrue; + grn_obj_unlink(context, column); + + return result; +} + static grn_table_cursor * rb_grn_table_open_grn_cursor (int argc, VALUE *argv, VALUE self, grn_ctx **context) @@ -2012,6 +2051,8 @@ rb_grn_table_get_column, 1); rb_define_method(rb_cGrnTable, "columns", rb_grn_table_get_columns, -1); + rb_define_method(rb_cGrnTable, "have_column?", + rb_grn_table_have_column, 1); rb_define_method(rb_cGrnTable, "open_cursor", rb_grn_table_open_cursor, -1); rb_define_method(rb_cGrnTable, "records", rb_grn_table_get_records, -1); Modified: groonga/trunk/test/test-table.rb (+8 -0) =================================================================== --- groonga/trunk/test/test-table.rb 2010-03-21 22:56:43 +09:00 (rev 1047) +++ groonga/trunk/test/test-table.rb 2010-03-24 23:50:30 +09:00 (rev 1048) @@ -654,6 +654,14 @@ users["morita"].attributes) end + def test_have_column + users = Groonga::Hash.create(:name => "Users", + :key_type => "ShortText") + users.define_column("name", "ShortText") + assert_true(users.have_column?("name"), "name") + assert_false(users.have_column?("description"), "description") + end + private def create_bookmarks bookmarks = Groonga::Array.create(:name => "Bookmarks") From null at cozmixng.org Wed Mar 24 11:05:39 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 25 Mar 2010 00:05:39 +0900 Subject: [groonga-commit:967] groonga [groonga (trunk) r1049] * don't show GRN_OBJ_UNIT_* without GRN_OBJ_WITH_SUBREC flag Message-ID: <20100324150539.19F381D1C27@mail.cozmixng.org> retro 2010-03-25 00:05:38 +0900 (Thu, 25 Mar 2010) New Revision: 1049 Log: * don't show GRN_OBJ_UNIT_* without GRN_OBJ_WITH_SUBREC flag in inspect. Modified files: groonga/trunk/ext/rb-grn-object.c Modified: groonga/trunk/ext/rb-grn-object.c (+15 -14) =================================================================== --- groonga/trunk/ext/rb-grn-object.c 2010-03-24 23:48:41 +09:00 (rev 1048) +++ groonga/trunk/ext/rb-grn-object.c 2010-03-25 00:05:38 -15:00 (rev 1049) @@ -756,23 +756,24 @@ if (flags & GRN_OBJ_WITH_BUFFER) rb_ary_push(inspected_flags, rb_str_new2("WITH_BUFFER")); - if (flags & GRN_OBJ_UNIT_DOCUMENT_SECTION) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_SECTION")); - if (flags & GRN_OBJ_UNIT_DOCUMENT_POSITION) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_POSITION")); + if (flags & GRN_OBJ_WITH_SUBREC) { + rb_ary_push(inspected_flags, rb_str_new2("WITH_SUBREC")); - if (flags & GRN_OBJ_UNIT_SECTION_POSITION) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_SECTION_POSITION")); + if (flags & GRN_OBJ_UNIT_DOCUMENT_SECTION) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_SECTION")); + if (flags & GRN_OBJ_UNIT_DOCUMENT_POSITION) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_POSITION")); - if (flags & GRN_OBJ_UNIT_USERDEF_DOCUMENT) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_DOCUMENT")); - if (flags & GRN_OBJ_UNIT_USERDEF_SECTION) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_SECTION")); - if (flags & GRN_OBJ_UNIT_USERDEF_POSITION) - rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_POSITION")); + if (flags & GRN_OBJ_UNIT_SECTION_POSITION) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_SECTION_POSITION")); - if (flags & GRN_OBJ_WITH_SUBREC) - rb_ary_push(inspected_flags, rb_str_new2("WITH_SUBREC")); + if (flags & GRN_OBJ_UNIT_USERDEF_DOCUMENT) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_DOCUMENT")); + if (flags & GRN_OBJ_UNIT_USERDEF_SECTION) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_SECTION")); + if (flags & GRN_OBJ_UNIT_USERDEF_POSITION) + rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_POSITION")); + } rb_str_cat2(inspected, "<"); rb_str_concat(inspected, rb_ary_join(inspected_flags, rb_str_new2("|"))); From null at cozmixng.org Wed Mar 24 11:20:32 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 25 Mar 2010 00:20:32 +0900 Subject: [groonga-commit:968] groonga [groonga (trunk) r1050] * accept "Table._key" as index name in Schema. Message-ID: <20100324152032.520E51D1C28@mail.cozmixng.org> retro 2010-03-25 00:20:31 +0900 (Thu, 25 Mar 2010) New Revision: 1050 Log: * accept "Table._key" as index name in Schema. Modified files: groonga/trunk/lib/groonga/schema.rb groonga/trunk/test/test-schema.rb Modified: groonga/trunk/test/test-schema.rb (+38 -3) =================================================================== --- groonga/trunk/test/test-schema.rb 2010-03-24 23:55:39 +09:00 (rev 1049) +++ groonga/trunk/test/test-schema.rb 2010-03-25 00:20:31 -15:00 (rev 1050) @@ -313,9 +313,7 @@ "path: <#{path}>, " + "domain: , " + "range: , " + - "flags: >", + "flags: >", index_column.inspect) end @@ -350,6 +348,43 @@ end end + def test_index_key + Groonga::Schema.create_table("Posts", + :type => :hash, + :key_type => "ShortText") do |table| + end + Groonga::Schema.create_table("Terms") do |table| + table.index "Posts._key", :with_position => true + end + + full_index_column_name = "Terms.Posts__key" + index_column = context[full_index_column_name] + assert_equal("#, " + + "name: <#{full_index_column_name}>, " + + "path: <#{index_column.path}>, " + + "domain: , " + + "range: , " + + "flags: >", + index_column.inspect) + end + + def test_index_key_again + Groonga::Schema.create_table("Posts", + :type => :hash, + :key_type => "ShortText") do |table| + end + Groonga::Schema.create_table("Terms") do |table| + table.index "Posts._key", :with_position => true + end + + assert_nothing_raised do + Groonga::Schema.create_table("Terms") do |table| + table.index "Posts._key" + end + end + end + def test_dump Groonga::Schema.define do |schema| schema.create_table("Posts") do |table| Modified: groonga/trunk/lib/groonga/schema.rb (+69 -36) =================================================================== --- groonga/trunk/lib/groonga/schema.rb 2010-03-24 23:55:39 +09:00 (rev 1049) +++ groonga/trunk/lib/groonga/schema.rb 2010-03-25 00:20:31 -15:00 (rev 1050) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2009 Kouhei Sutou +# Copyright (C) 2009-2010 Kouhei Sutou # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -494,9 +494,20 @@ self end - # _taget_column_??????????????????? - # ?? + # call-seq: + # table.index(target_column_full_name, options={}) + # table.index(target_table, target_column, options={}) # + # _target_table_?_target_column_?????????? + # ??????????? + # + # _target_column_full_name_????????????? + # ??????"."????????????Users???? + # ???name????????????????????? + # ???????? + # + # table.index("Users.name") + # # _options_?????????????? # # [+:name+] @@ -521,26 +532,24 @@ # # [+:with_position+] # ????????????????????? - def index(target_column, options={}) - name = options.delete(:name) - if name.nil? - target_column_name = nil - if target_column.is_a?(Groonga::Column) - target_column_name = target_column.name - else - target_column_name = target_column + def index(target_table_or_target_column_full_name, *args) + if args.size > 2 + n_args = args.size + 1 + raise ArgumentError, "wrong number of arguments (#{n_args} for 2 or 3)" + end + options = nil + options = args.pop if args.last.is_a?(::Hash) + if args.empty? + target_column_full_name = target_table_or_target_column_full_name + if target_column_full_name.is_a?(Groonga::Column) + target_column_full_name = target_column_full_name.name end - name = target_column_name.gsub(/\./, "_") + target_table, target_column = target_column_full_name.split(/\./, 2) + else + target_table = target_table_or_target_column_full_name + target_column = args.pop end - - definition = self[name, IndexColumnDefinition] - if definition.nil? - definition = IndexColumnDefinition.new(name, options) - update_definition(name, IndexColumnDefinition, definition) - end - definition.target = target_column - definition.options.merge!(column_options.merge(options)) - self + define_index(target_table, target_column, options || {}) end # ???_name_?32bit???????????????? @@ -732,6 +741,21 @@ def persistent? # :nodoc: @options[:persistent].nil? ? true : @options[:persistent] end + + def define_index(target_table, target_column, options) + name = options.delete(:name) + name ||= "#{target_table}_#{target_column}".gsub(/\./, "_") + + definition = self[name, IndexColumnDefinition] + if definition.nil? + definition = IndexColumnDefinition.new(name, options) + update_definition(name, IndexColumnDefinition, definition) + end + definition.target_table = target_table + definition.target_column = target_column + definition.options.merge!(column_options.merge(options)) + self + end end class TableRemoveDefinition # :nodoc: @@ -799,49 +823,58 @@ end class IndexColumnDefinition # :nodoc: - attr_accessor :name, :target + attr_accessor :name, :target_table, :target_column attr_reader :options def initialize(name, options={}) @name = name @name = @name.to_s if @name.is_a?(Symbol) @options = (options || {}).dup - @target = nil + @target_table = nil + @target_column = nil end def define(table_definition, table) - target = @target - unless target.is_a?(Groonga::Object) - target = table_definition.context[target] + target_name = "#{@target_table}.#{@target_column}" + target_table = table_definition.context[@target_table] + if target_table.nil? or + !(@target_column == "_key" or + target_table.have_column?(@target_column)) + raise ArgumentError, "Unknown index target: <#{target_name}>" end - if target.nil? - raise ArgumentError, "Unknown index target: #{@target.inspect}" - end index = table.column(@name) if index - return index if same_index?(table_definition, index, target) + return index if same_index?(table_definition, index) if @options.delete(:force) index.remove else raise ArgumentError, "the same name index column with " + "different target or options is " + - "already defined: #{target.inspect}(#{@options.inspect}): " + - "#{index.inspect}" + "already defined: #{target_name.inspect}" + + "(#{@options.inspect}): #{index.inspect}" end end index = table.define_index_column(@name, - target.table, + @target_table, @options) - index.source = target + index.source = target_table.column(@target_column) index end private - def same_index?(table_definition, index, target) + def same_index?(table_definition, index) context = table_definition.context # TODO: should check column type and other options. - index.range == target.table and index.sources == [target] + return false if index.range.name != @target_table + source_names = index.sources.collect do |source| + if source.nil? + "#{index.range.name}._key" + else + source.name + end + end + source_names == ["#{@target_table}.#{@target_column}"] end end From null at cozmixng.org Fri Mar 26 11:05:27 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Sat, 27 Mar 2010 00:05:27 +0900 Subject: [groonga-commit:969] groonga [rroonga r1053] * create tags and branches. Message-ID: <20100326150527.F003C1D1C2C@mail.cozmixng.org> retro 2010-03-27 00:05:27 +0900 (Sat, 27 Mar 2010) New Revision: 1053 Log: * create tags and branches. Added directories: rroonga/branches/ rroonga/tags/ Added: rroonga/branches/ Added: rroonga/tags/ From null at cozmixng.org Fri Mar 26 11:05:26 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Sat, 27 Mar 2010 00:05:26 +0900 Subject: [groonga-commit:970] groonga r1052: * move trunk to rroonga. Message-ID: <20100326150526.7B49C1D1C27@mail.cozmixng.org> retro 2010-03-27 00:05:25 +0900 (Sat, 27 Mar 2010) New Revision: 1052 Log: * move trunk to rroonga. Copied directories: rroonga/trunk/ (from rev 1051, groonga/trunk/) Removed directories: groonga/trunk/ Copied: rroonga/trunk/ (from rev 1051, groonga/trunk/) Deleted: groonga/trunk/ % svn ls groonga/trunk/@1051 From null at cozmixng.org Fri Mar 26 12:05:51 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Sat, 27 Mar 2010 01:05:51 +0900 Subject: [groonga-commit:971] groonga [rroonga (trunk) r1055] * groonga -> rroonga. Message-ID: <20100326160551.3CBE81D1C2C@mail.cozmixng.org> retro 2010-03-27 01:05:50 +0900 (Sat, 27 Mar 2010) New Revision: 1055 Log: * groonga -> rroonga. Modified files: rroonga/trunk/Rakefile Modified: rroonga/trunk/Rakefile (+5 -5) =================================================================== --- rroonga/trunk/Rakefile 2010-03-26 22:59:55 +09:00 (rev 1054) +++ rroonga/trunk/Rakefile 2010-03-27 01:05:50 -15:00 (rev 1055) @@ -1,6 +1,6 @@ # -*- coding: utf-8; mode: ruby -*- # -# Copyright (C) 2009 Kouhei Sutou +# Copyright (C) 2009-2010 Kouhei Sutou # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -86,7 +86,7 @@ ENV["VERSION"] ||= guess_version version = ENV["VERSION"] project = nil -Hoe.spec('groonga') do |_project| +Hoe.spec('rroonga') do |_project| Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb" project = _project project.version = version @@ -118,7 +118,7 @@ description = cleanup_white_space(entries[entries.index("Description") + 1]) project.summary, project.description, = description.split(/\n\n+/, 3) - project.remote_rdoc_dir = "groonga" + project.remote_rdoc_dir = "rroonga" end project.spec.dependencies.delete_if {|dependency| dependency.name == "hoe"} @@ -140,7 +140,7 @@ options = rdoc_task.options t_option_index = options.index("--title") || options.index("-t") rdoc_task.options[t_option_index, 2] = nil - rdoc_task.title = "Ruby/groonga - #{version}" + rdoc_task.title = "rroonga - #{version}" rdoc_task.rdoc_files = ["ext/rb-groonga.c"] + Dir.glob("ext/rb-grn-*.c") rdoc_task.rdoc_files += Dir.glob("lib/**/*.rb") @@ -204,7 +204,7 @@ end task :tag do - repository = "svn+ssh://rubyforge.org/var/svn/groonga/groonga" + repository = "svn+ssh://rubyforge.org/var/svn/groonga/rroonga" sh("svn cp -m 'release #{version}!!!' " + "#{repository}/trunk #{repository}/tags/#{version}") end From null at cozmixng.org Fri Mar 26 12:05:52 2010 From: null at cozmixng.org (null at cozmixng.org) Date: Sat, 27 Mar 2010 01:05:52 +0900 Subject: [groonga-commit:972] groonga [rroonga (trunk) r1056] * groonga -> rroonga. Message-ID: <20100326160552.A5D781D1C2D@mail.cozmixng.org> retro 2010-03-27 01:05:52 +0900 (Sat, 27 Mar 2010) New Revision: 1056 Log: * groonga -> rroonga. Modified files: rroonga/trunk/html/developer.html rroonga/trunk/html/index.html Modified: rroonga/trunk/html/index.html (+15 -15) =================================================================== --- rroonga/trunk/html/index.html 2010-03-26 23:01:56 +09:00 (rev 1055) +++ rroonga/trunk/html/index.html 2010-03-27 01:05:52 -15:00 (rev 1056) @@ -20,9 +20,9 @@ @@ -35,35 +35,35 @@ groonga????Ruby???????????????????????????

-

Ruby/groonga

+

rroonga

- Ruby/groonga?groonga?????DB-API??????Ruby??????????DB-API????????QL-API??????????ActiveGroonga??????? + rroonga?groonga?????DB-API??????Ruby??????????DB-API????????QL-API??????????ActiveGroonga???????

-

Ruby/groonga???????

+

rroonga???????

2010-02-09????????0.9.1??????

-

Ruby/groonga???????

+

rroonga???????

RubyGems????????????groonga????????????????????????????????????

-
% sudo gem install groonga
+
% sudo gem install rroonga
-

Ruby/groonga???????

+

rroonga???????

????????????????????????? ?????????????????????

ActiveGroonga

- ActiveGroonga?Ruby/groonga??????????????????????????????????????????? + ActiveGroonga?rroonga??????????????????????????????????????????? ActiveRecord????API?groonga?????????????????????????????

@@ -99,11 +99,11 @@

?????

- Ruby/groonga???ActiveGroonga?????????????????? Free Software Foundation?????GNU Lesser General Public License 2.1??????????????????????????????????? + rroonga???ActiveGroonga?????????????????? Free Software Foundation?????GNU Lesser General Public License 2.1???????????????????????????????????

- Ruby/groonga???ActiveGroonga????????????????????????????????????????????????????????????????????GNU Lesser General Public License 2.1????????? + rroonga???ActiveGroonga????????????????????????????????????????????????????????????????????GNU Lesser General Public License 2.1?????????

@@ -37,31 +37,27 @@

?????

- Ruby/groonga?ActiveGroonga???????RubyForge??????? + rroonga?ActiveGroonga???????RubyForge??????? Subversion??????????????????????????????

-
Ruby/groonga
-
% svn co http://groonga.rubyforge.org/svn/groonga/trunk groonga
+
rroonga
+
% svn co http://groonga.rubyforge.org/svn/rroonga/trunk rroonga
ActiveGroonga
% svn co http://groonga.rubyforge.org/svn/activegroonga/trunk activegroonga

- Ruby/groonga???ActiveGroonga?????????????????????????? + rroonga???ActiveGroonga?????????????????????????? ????????????????????????????

-
% svn co http://groonga.rubyforge.org/svn/examples groonga-examples
+
% svn co http://groonga.rubyforge.org/svn/examples ranguba-examples

?????????????

- ?????groonga????????????????? + ?????groonga????????????Redmine???????? ????????????????groonga?????????????????

-

- ?????????????????????RubyForge???????????????? - ?????????????????????????????? -

???????

@@ -72,7 +68,7 @@

??????

???????????????RDoc????????? - ????????????HTML????????????????????????? + ????????????HTML?????????????????????????

????????????????????????????????????????????????? @@ -94,7 +90,7 @@