From null at cozmixng.org Tue Aug 11 09:30:38 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 11 Aug 2009 22:30:38 +0900 Subject: [groonga-commit:594] groonga [groonga (trunk) r630] * follow the recent grn_obj_column() changes. Message-ID: <20090811133038.EE25F1D1C6D@mail.cozmixng.org> retro 2009-08-11 22:30:38 +0900 (Tue, 11 Aug 2009) New Revision: 630 Log: * follow the recent grn_obj_column() changes. Modified files: groonga/trunk/ext/rb-grn-expression.c groonga/trunk/lib/groonga/expression-builder.rb groonga/trunk/lib/groonga/record.rb groonga/trunk/test/groonga-test-utils.rb groonga/trunk/test/test-record.rb groonga/trunk/test/test-table.rb Modified: groonga/trunk/test/groonga-test-utils.rb (+1 -0) =================================================================== --- groonga/trunk/test/groonga-test-utils.rb 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/test/groonga-test-utils.rb 2009-08-11 22:30:38 +09:00 (rev 630) @@ -15,6 +15,7 @@ require 'fileutils' require 'pathname' +require 'time' require 'groonga' Modified: groonga/trunk/ext/rb-grn-expression.c (+37 -0) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-11 22:30:38 +09:00 (rev 630) @@ -220,6 +220,40 @@ } static VALUE +rb_grn_expression_parse (int argc, VALUE *argv, VALUE self) +{ + grn_ctx *context = NULL; + grn_obj *expression, *table, *default_column = NULL; + grn_rc rc; + char *query = NULL; + unsigned query_size = 0; + VALUE options, rb_query, rb_table, rb_default_column; + + rb_scan_args(argc, argv, "11", &rb_query, &options); + rb_grn_scan_options(options, + "table", &rb_table, + "default_column", &rb_default_column, + NULL); + + query = StringValuePtr(rb_query); + query_size = RSTRING_LEN(rb_query); + + rb_grn_expression_deconstruct(SELF(self), &expression, &context, + NULL, NULL, + NULL, NULL, NULL); + + table = RVAL2GRNOBJECT(rb_table, &context); + default_column = RVAL2GRNBULK(rb_default_column, context, default_column); + rc = grn_expr_parse(context, expression, query, query_size, + table, default_column); + if (rc != GRN_SUCCESS) + rb_grn_context_check(context, + rb_ary_new3(2, self, rb_ary_new4(argc, argv))); + + return Qnil; +} + +static VALUE rb_grn_expression_execute (VALUE self) { grn_ctx *context = NULL; @@ -301,6 +335,9 @@ rb_define_method(rb_cGrnExpression, "append_operation", rb_grn_expression_append_operation, 2); + rb_define_method(rb_cGrnExpression, "parse", + rb_grn_expression_parse, -1); + rb_define_method(rb_cGrnExpression, "execute", rb_grn_expression_execute, 0); rb_define_method(rb_cGrnExpression, "compile", Modified: groonga/trunk/test/test-record.rb (+2 -2) =================================================================== --- groonga/trunk/test/test-record.rb 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/test/test-record.rb 2009-08-11 22:30:38 +09:00 (rev 630) @@ -122,14 +122,14 @@ def test_get_nonexistent_column groonga = @bookmarks.add - assert_raise(Groonga::Error) do + assert_raise(Groonga::InvalidArgument) do groonga["nonexistent"] end end def test_set_nonexistent_column groonga = @bookmarks.add - assert_raise(Groonga::Error) do + assert_raise(Groonga::InvalidArgument) do groonga["nonexistent"] = "value" end end Modified: groonga/trunk/lib/groonga/record.rb (+12 -14) =================================================================== --- groonga/trunk/lib/groonga/record.rb 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/lib/groonga/record.rb 2009-08-11 22:30:38 +09:00 (rev 630) @@ -34,27 +34,29 @@ end def [](column_name) - column(column_name, true)[@id] + column(column_name)[@id] end def []=(column_name, value) - column(column_name, true)[@id] = value + column(column_name)[@id] = value end def append(column_name, value) - column(column_name, true).append(@id, value) + column(column_name).append(@id, value) end def have_column?(name) - not column(name).nil? + column(name).is_a?(Groonga::Column) + rescue Groonga::InvalidArgument + false end def reference_column?(name) - column(name, true).range.is_a?(Groonga::Table) + column(name).range.is_a?(Groonga::Table) end def search(name, query, options={}) - column(name, true).search(query, options) + column(name).search(query, options) end def key @@ -74,11 +76,11 @@ end def increment!(name, delta=nil) - column(name, true).increment!(@id, delta) + column(name).increment!(@id, delta) end def decrement!(name, delta=nil) - column(name, true).decrement!(@id, delta) + column(name).decrement!(@id, delta) end def columns @@ -116,12 +118,8 @@ end private - def column(name, required=false) - _column = @table.column(name.to_s) - if _column.nil? and required - raise Groonga::Error, "nonexistent column: <#{name.inspect}>" - end - _column + def column(name) + @table.column(name.to_s) end end end Modified: groonga/trunk/test/test-table.rb (+22 -0) =================================================================== --- groonga/trunk/test/test-table.rb 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/test/test-table.rb 2009-08-11 22:30:38 +09:00 (rev 630) @@ -382,6 +382,28 @@ results.collect {|record| record["id"]}) end + def test_select_sub_expression + comments = Groonga::Array.create(:name => "comments") + comments.define_column("content", "Text") + comments.define_column("created_at", "Time") + terms = Groonga::PatriciaTrie.create(:name => "terms") + terms.define_index_column("comment_content", comments, + :with_section => true, + :source => "comments.content") + comment1 = comments.add(:content => "Hello Good-bye!", + :created_at => Time.parse("2009-08-09")) + comment2 = comments.add(:content => "Hello World", + :created_at => Time.parse("2009-07-09")) + comment3 = comments.add(:content => "test", + :created_at => Time.parse("2009-06-09")) + result = comments.select do |record| + (record.match("Hello", "content")) & + (record["created_at"] < Time.parse("2009-08-01")) + end + assert_equal([comment2], + result.collect {|record| record.key}) + end + def test_select_without_block comments = Groonga::Array.create(:name => "comments") comment1 = comments.add Modified: groonga/trunk/lib/groonga/expression-builder.rb (+19 -0) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-01 01:31:06 -15:00 (rev 629) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-11 22:30:38 +09:00 (rev 630) @@ -140,6 +140,21 @@ super(Groonga::Operation::GREATER_EQUAL, column_name, value) end end + + class SubExpressionBuilder < ExpressionBuilder + def initialize(table, column_name, query) + super() + @table = table + @column_name = column_name + @query = query + end + + def build(expression, variable) + expression.parse(@query, + :table => @table, + :default_column => @column_name) + end + end end class RecordExpressionBuilder @@ -160,6 +175,10 @@ end ColumnExpressionBuilder.new(column, nil, nil) end + + def match(query, column_name=nil) + SubExpressionBuilder.new(@table, column_name, query) + end end class ColumnExpressionBuilder From null at cozmixng.org Tue Aug 11 10:45:46 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 11 Aug 2009 23:45:46 +0900 Subject: [groonga-commit:595] groonga [groonga (trunk) r632] * follow the recent grn_obj_column() changes. Message-ID: <20090811144546.AF9671D1C6D@mail.cozmixng.org> retro 2009-08-11 23:45:46 +0900 (Tue, 11 Aug 2009) New Revision: 632 Log: * follow the recent grn_obj_column() changes. Modified files: groonga/trunk/test/test-table.rb Modified: groonga/trunk/test/test-table.rb (+3 -1) =================================================================== --- groonga/trunk/test/test-table.rb 2009-08-11 23:39:28 +09:00 (rev 631) +++ groonga/trunk/test/test-table.rb 2009-08-11 23:45:46 +09:00 (rev 632) @@ -154,7 +154,9 @@ table_path = @tables_dir + "bookmarks" table = Groonga::Hash.create(:name => "bookmarks", :path => table_path.to_s) - assert_nil(table.column("nonexistent")) + assert_raise(Groonga::InvalidArgument) do + table.column("nonexistent") + end end def test_set_value From null at cozmixng.org Tue Aug 11 10:45:44 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 11 Aug 2009 23:45:44 +0900 Subject: [groonga-commit:596] groonga [groonga (trunk) r631] * implement Groonga::PatriciaTrie#scan. Message-ID: <20090811144544.BE32D1D1C25@mail.cozmixng.org> retro 2009-08-11 23:45:44 +0900 (Tue, 11 Aug 2009) New Revision: 631 Log: * implement Groonga::PatriciaTrie#scan. Modified files: groonga/trunk/ext/rb-grn-patricia-trie.c groonga/trunk/test/test-patricia-trie.rb Modified: groonga/trunk/ext/rb-grn-patricia-trie.c (+61 -0) =================================================================== --- groonga/trunk/ext/rb-grn-patricia-trie.c 2009-08-11 22:30:21 +09:00 (rev 630) +++ groonga/trunk/ext/rb-grn-patricia-trie.c 2009-08-11 23:45:44 +09:00 (rev 631) @@ -150,6 +150,65 @@ return rb_result; } +static VALUE +rb_grn_patricia_trie_scan (VALUE self, VALUE rb_string) +{ + grn_ctx *context; + grn_obj *table; + VALUE rb_result = Qnil; + grn_pat_scan_hit hits[1024]; + const char *string; + long string_length; + rb_grn_boolean block_given; + + string = StringValuePtr(rb_string); + string_length = RSTRING_LEN(rb_string); + + rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, + NULL, NULL, NULL, + NULL, NULL, NULL); + + block_given = rb_block_given_p(); + if (!block_given) + rb_result = rb_ary_new(); + + while (string_length > 0) { + const char *rest; + int i, n_hits; + long previous_offset = 0; + + n_hits = grn_pat_scan(context, (grn_pat *)table, + string, string_length, + hits, sizeof(hits) / sizeof(*hits), + &rest); + for (i = 0; i < n_hits; i++) { + VALUE record, term, matched_info; + + if (hits[i].offset < previous_offset) + continue; + + record = rb_grn_record_new(self, hits[i].id, Qnil); + term = rb_str_new(string + hits[i].offset, + hits[i].length); + matched_info = rb_ary_new3(4, + term, + record, + UINT2NUM(hits[i].offset), + UINT2NUM(hits[i].length)); + if (block_given) { + rb_yield(matched_info); + } else { + rb_ary_push(rb_result, matched_info); + } + previous_offset = hits[i].offset; + } + string_length -= rest - string; + string = rest; + } + + return rb_result; +} + void rb_grn_init_patricia_trie (VALUE mGrn) { @@ -162,4 +221,6 @@ rb_define_method(rb_cGrnPatriciaTrie, "search", rb_grn_patricia_trie_search, -1); + rb_define_method(rb_cGrnPatriciaTrie, "scan", + rb_grn_patricia_trie_scan, 1); } Modified: groonga/trunk/test/test-patricia-trie.rb (+16 -0) =================================================================== --- groonga/trunk/test/test-patricia-trie.rb 2009-08-11 22:30:21 +09:00 (rev 630) +++ groonga/trunk/test/test-patricia-trie.rb 2009-08-11 23:45:44 +09:00 (rev 631) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright (C) 2009 Kouhei Sutou # # This library is free software; you can redistribute it and/or @@ -88,4 +89,19 @@ users.add("morita") assert_true(users.has_key?("morita")) end + + def test_scan + Groonga::Context.default_options = {:encoding => "utf-8"} + words = Groonga::PatriciaTrie.create(:key_type => "ShortText", + :key_normalize => true) + words.add("???") + adventure_of_link = words.add('??????') + words.add('??') + gaxtu = words.add('???') + muteki = words.add('??????') + assert_equal([["muTEki", muteki, 0, 6], + ["??????", adventure_of_link, 7, 18], + ["??", gaxtu, 42, 6]], + words.scan('muTEki ?????? ????? ??')) + end end From null at cozmixng.org Wed Aug 12 08:45:49 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Wed, 12 Aug 2009 21:45:49 +0900 Subject: [groonga-commit:597] groonga [groonga (trunk) r633] * follow the recent groonga changes. Message-ID: <20090812124550.206D61D1C25@mail.cozmixng.org> retro 2009-08-12 21:45:49 +0900 (Wed, 12 Aug 2009) New Revision: 633 Log: * follow the recent groonga changes. Modified files: groonga/trunk/ext/rb-grn-expression.c groonga/trunk/ext/rb-grn-table.c groonga/trunk/lib/groonga/expression-builder.rb groonga/trunk/test/test-table.rb Modified: groonga/trunk/ext/rb-grn-table.c (+7 -3) =================================================================== --- groonga/trunk/ext/rb-grn-table.c 2009-08-11 23:41:40 +09:00 (rev 632) +++ groonga/trunk/ext/rb-grn-table.c 2009-08-12 21:45:49 +09:00 (rev 633) @@ -813,9 +813,9 @@ grn_obj *result; grn_table_sort_key *keys; int i, n_keys; - int n_records, limit = 0; + int n_records, offset = 0, limit = -1; VALUE rb_keys, options; - VALUE rb_limit; + VALUE rb_offset, rb_limit; VALUE *rb_sort_keys; grn_table_cursor *cursor; VALUE rb_result; @@ -876,15 +876,19 @@ } rb_grn_scan_options(options, + "offset", &rb_offset, "limit", &rb_limit, NULL); + if (!NIL_P(rb_offset)) + offset = NUM2INT(rb_offset); if (!NIL_P(rb_limit)) limit = NUM2INT(rb_limit); result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_NO_KEY, NULL, table); - n_records = grn_table_sort(context, table, limit, result, keys, n_keys); + n_records = grn_table_sort(context, table, offset, limit, + result, keys, n_keys); rb_result = rb_ary_new(); cursor = grn_table_cursor_open(context, result, NULL, 0, NULL, 0, Modified: groonga/trunk/ext/rb-grn-expression.c (+17 -5) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-11 23:41:40 +09:00 (rev 632) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-12 21:45:49 +09:00 (rev 633) @@ -223,16 +223,22 @@ rb_grn_expression_parse (int argc, VALUE *argv, VALUE self) { grn_ctx *context = NULL; - grn_obj *expression, *table, *default_column = NULL; + grn_obj *expression, *default_column = NULL; + grn_operator default_operator = GRN_OP_AND; + grn_operator default_mode = GRN_OP_MATCH; grn_rc rc; char *query = NULL; unsigned query_size = 0; - VALUE options, rb_query, rb_table, rb_default_column; + int parse_level = 0; + VALUE options, rb_query, rb_default_column, rb_default_operator; + VALUE rb_default_mode, rb_use_pragma; rb_scan_args(argc, argv, "11", &rb_query, &options); rb_grn_scan_options(options, - "table", &rb_table, "default_column", &rb_default_column, + "default_operator", &rb_default_operator, + "default_mode", &rb_default_mode, + "use_pragma", &rb_use_pragma, NULL); query = StringValuePtr(rb_query); @@ -242,10 +248,16 @@ NULL, NULL, NULL, NULL, NULL); - table = RVAL2GRNOBJECT(rb_table, &context); default_column = RVAL2GRNBULK(rb_default_column, context, default_column); + if (!NIL_P(rb_default_mode)) + default_mode = RVAL2GRNOPERATOR(rb_default_mode); + if (!NIL_P(rb_default_operator)) + default_operator = RVAL2GRNOPERATOR(rb_default_operator); + if (RVAL2CBOOL(rb_use_pragma)) + parse_level = 2; rc = grn_expr_parse(context, expression, query, query_size, - table, default_column); + default_column, default_mode, default_operator, + parse_level); if (rc != GRN_SUCCESS) rb_grn_context_check(context, rb_ary_new3(2, self, rb_ary_new4(argc, argv))); Modified: groonga/trunk/test/test-table.rb (+1 -1) =================================================================== --- groonga/trunk/test/test-table.rb 2009-08-11 23:41:40 +09:00 (rev 632) +++ groonga/trunk/test/test-table.rb 2009-08-12 21:45:49 +09:00 (rev 633) @@ -399,7 +399,7 @@ comment3 = comments.add(:content => "test", :created_at => Time.parse("2009-06-09")) result = comments.select do |record| - (record.match("Hello", "content")) & + record.match("Hello", "content") & (record["created_at"] < Time.parse("2009-08-01")) end assert_equal([comment2], Modified: groonga/trunk/lib/groonga/expression-builder.rb (+10 -8) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-11 23:41:40 +09:00 (rev 632) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-12 21:45:49 +09:00 (rev 633) @@ -142,17 +142,14 @@ end class SubExpressionBuilder < ExpressionBuilder - def initialize(table, column_name, query) + def initialize(query, options) super() - @table = table - @column_name = column_name @query = query + @options = options end def build(expression, variable) - expression.parse(@query, - :table => @table, - :default_column => @column_name) + expression.parse(@query, @options) end end end @@ -176,8 +173,13 @@ ColumnExpressionBuilder.new(column, nil, nil) end - def match(query, column_name=nil) - SubExpressionBuilder.new(@table, column_name, query) + def match(query, options_or_default_column={}) + if options_or_default_column.is_a?(String) + options = {:default_column => options_or_default_column} + else + options = options_or_default_column + end + SubExpressionBuilder.new(query, options) end end From null at cozmixng.org Fri Aug 14 09:45:29 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 14 Aug 2009 22:45:29 +0900 Subject: [groonga-commit:598] groonga [groonga (trunk) r634] * bind grn_expr_inspect() experimentally. Message-ID: <20090814134529.ED6E51D1C25@mail.cozmixng.org> retro 2009-08-14 22:45:29 +0900 (Fri, 14 Aug 2009) New Revision: 634 Log: * bind grn_expr_inspect() experimentally. Modified files: groonga/trunk/ext/rb-grn-expression.c Modified: groonga/trunk/ext/rb-grn-expression.c (+30 -0) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-12 21:33:32 +09:00 (rev 633) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-14 22:45:29 +09:00 (rev 634) @@ -330,6 +330,33 @@ return Qnil; } +/* REMOVE ME */ +grn_rc grn_expr_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *expr); + +static VALUE +rb_grn_expression_inspect (VALUE self) +{ + grn_rc rc; + grn_ctx *context = NULL; + grn_obj inspected; + grn_obj *expression; + VALUE rb_inspected; + + rb_grn_expression_deconstruct(SELF(self), &expression, &context, + NULL, NULL, + NULL, NULL, NULL); + + GRN_TEXT_INIT(&inspected, 0); + GRN_TEXT_PUTS(context, &inspected, "#"); + rb_inspected = rb_str_new(GRN_TEXT_VALUE(&inspected), + GRN_TEXT_LEN(&inspected)); + GRN_OBJ_FIN(context, &inspected); + + return rb_inspected; +} + void rb_grn_init_expression (VALUE mGrn) { @@ -360,4 +387,7 @@ rb_define_method(rb_cGrnExpression, "[]", rb_grn_expression_array_reference, 1); + + rb_define_method(rb_cGrnExpression, "inspect", + rb_grn_expression_inspect, 0); } From null at cozmixng.org Mon Aug 24 22:51:04 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 25 Aug 2009 11:51:04 +0900 Subject: [groonga-commit:599] groonga [groonga (trunk) r635] follow the recent groonga changes: Message-ID: <20090825025104.E92BC1D1C80@mail.cozmixng.org> retro 2009-08-25 11:51:04 +0900 (Tue, 25 Aug 2009) New Revision: 635 Log: follow the recent groonga changes: grn_expr_exec grn_expr_append_obj grn_expr_append_const Modified files: groonga/trunk/ext/rb-grn-column.c groonga/trunk/ext/rb-grn-expression.c Modified: groonga/trunk/ext/rb-grn-expression.c (+30 -26) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-14 22:32:25 +09:00 (rev 634) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-25 11:51:04 +09:00 (rev 635) @@ -151,49 +151,52 @@ } static VALUE -rb_grn_expression_get_value (VALUE self, VALUE rb_offset) +rb_grn_expression_append_object (int argc, VALUE *argv, VALUE self) { + VALUE rb_object, rb_operation, rb_n_arguments; grn_ctx *context = NULL; - grn_obj *value, *expression; - int offset; + grn_obj *expression, *object; + grn_operator operation = GRN_OP_PUSH; + int n_arguments = 1; - rb_grn_expression_deconstruct(SELF(self), &expression, &context, - NULL, NULL, - NULL, NULL, NULL); + rb_scan_args(argc, argv, "12", &rb_object, &rb_operation, &rb_n_arguments); + if (!NIL_P(rb_operation)) + operation = NUM2INT(rb_operation); + if (!NIL_P(rb_n_arguments)) + n_arguments = NUM2INT(rb_n_arguments); - offset = NUM2INT(rb_offset); - value = grn_expr_get_value(context, expression, offset); - return GRNBULK2RVAL(context, value, self); -} - -static VALUE -rb_grn_expression_append_object (VALUE self, VALUE rb_object) -{ - grn_ctx *context = NULL; - grn_obj *expression, *object; - rb_grn_expression_deconstruct(SELF(self), &expression, &context, NULL, NULL, NULL, NULL, NULL); object = RVAL2GRNOBJECT(rb_object, &context); - grn_expr_append_obj(context, expression, object); + grn_expr_append_obj(context, expression, object, + operation, n_arguments); rb_grn_context_check(context, self); return self; } static VALUE -rb_grn_expression_append_constant (VALUE self, VALUE rb_constant) +rb_grn_expression_append_constant (int argc, VALUE *argv, VALUE self) { + VALUE rb_constant, rb_operator, rb_n_arguments; grn_ctx *context = NULL; grn_obj *expression, *constant = NULL; + grn_operator operator = GRN_OP_PUSH; + int n_arguments = 1; + rb_scan_args(argc, argv, "12", &rb_constant, &rb_operator, &rb_n_arguments); + if (!NIL_P(rb_operator)) + operator = NUM2INT(rb_operator); + if (!NIL_P(rb_n_arguments)) + n_arguments = NUM2INT(rb_n_arguments); + rb_grn_expression_deconstruct(SELF(self), &expression, &context, NULL, NULL, NULL, NULL, NULL); RVAL2GRNOBJ(rb_constant, context, &constant); - grn_expr_append_const(context, expression, constant); + grn_expr_append_const(context, expression, constant, operator, n_arguments); grn_obj_close(context, constant); rb_grn_context_check(context, self); return self; @@ -269,14 +272,18 @@ rb_grn_expression_execute (VALUE self) { grn_ctx *context = NULL; - grn_obj *expression, *result; + grn_obj *expression; + grn_rc rc; rb_grn_expression_deconstruct(SELF(self), &expression, &context, NULL, NULL, NULL, NULL, NULL); - result = grn_expr_exec(context, expression); - return GRNOBJ2RVAL(Qnil, context, result, self); + rc = grn_expr_exec(context, expression, 0); + rb_grn_context_check(context, self); + rb_grn_rc_check(rc, self); + + return Qnil; } static VALUE @@ -382,9 +389,6 @@ rb_define_method(rb_cGrnExpression, "compile", rb_grn_expression_compile, 0); - rb_define_method(rb_cGrnExpression, "value", - rb_grn_expression_get_value, 1); - rb_define_method(rb_cGrnExpression, "[]", rb_grn_expression_array_reference, 1); Modified: groonga/trunk/ext/rb-grn-column.c (+1 -3) =================================================================== --- groonga/trunk/ext/rb-grn-column.c 2009-08-14 22:32:25 +09:00 (rev 634) +++ groonga/trunk/ext/rb-grn-column.c 2009-08-25 11:51:04 +09:00 (rev 635) @@ -167,7 +167,6 @@ grn_ctx *context; grn_obj *table, *column, *result, *expression; grn_operator operator = GRN_OP_OR; - grn_rc rc; VALUE options; VALUE rb_query, rb_name, rb_operator, rb_result; char *name = NULL, *query; @@ -210,9 +209,8 @@ expression = grn_expr_create_from_str(context, name, name_size, query, query_size, table, column); - rc = grn_table_select(context, table, expression, result, operator); + grn_table_select(context, table, expression, result, operator); rb_grn_context_check(context, self); - rb_grn_rc_check(rc, self); return rb_result; } From null at cozmixng.org Tue Aug 25 03:05:36 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 25 Aug 2009 16:05:36 +0900 Subject: [groonga-commit:600] groonga [groonga (trunk) r636] add grnop2ruby.rb: extract grn_operator from groonga.h Message-ID: <20090825070536.E82231D1C9C@mail.cozmixng.org> retro 2009-08-25 16:05:36 +0900 (Tue, 25 Aug 2009) New Revision: 636 Log: add grnop2ruby.rb: extract grn_operator from groonga.h Added directories: groonga/trunk/misc/ Added files: groonga/trunk/misc/grnop2ruby.rb Added: groonga/trunk/misc/ Added: groonga/trunk/misc/grnop2ruby.rb (+49 -0) =================================================================== --- groonga/trunk/misc/grnop2ruby.rb 2009-08-25 11:43:51 +09:00 (rev 635) +++ groonga/trunk/misc/grnop2ruby.rb 2009-08-25 16:05:36 +09:00 (rev 636) @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 Yuto Hayamizu +# +# 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 + +# +# This script expects "groonga.h" as a first argument, extracts the +# 'grn_operator', and write 'rb_define_const's of 'grn_operator' to +# standard outout. +# +# Usage: +# ruby grnop2ruby.rb /path/to/groonga.h +# + +replace_dictionary = { + "VAR" => "VARIABLE", + "EXPR" => "EXPRESSION", + "NOP" => "NO_OPERATION", + "REF" => "REFERENCE", + "OBJ" => "OBJECT", + "INCR" => "INCREMENT", + "DECR" => "DECREMENT", + "MOD" => "MODULO", + "LCP" => "LONGEST_COMMON_PREFIX", +} + +ARGF.each_line do |line| + case line + when /\A\s+(GRN_OP_\w+)/ + operator = $1 + rb_operator = operator.gsub(/\AGRN_OP_/, "").split("_").map{ |word| + replace_dictionary[word] || word + }.join("_") + puts " rb_define_const(rb_mGrnOperation, \"%s\", + UINT2NUM(%s));" % [rb_operator, operator] + end +end From null at cozmixng.org Tue Aug 25 03:05:38 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 25 Aug 2009 16:05:38 +0900 Subject: [groonga-commit:601] groonga [groonga (trunk) r637] follow the recent groonga changes Message-ID: <20090825070538.EDDA21D1CBF@mail.cozmixng.org> retro 2009-08-25 16:05:38 +0900 (Tue, 25 Aug 2009) New Revision: 637 Log: follow the recent groonga changes Modified files: groonga/trunk/ext/rb-grn-context.c groonga/trunk/ext/rb-grn-expression.c groonga/trunk/ext/rb-grn-object.c groonga/trunk/ext/rb-grn-operation.c groonga/trunk/ext/rb-grn-table.c groonga/trunk/lib/groonga/expression-builder.rb groonga/trunk/lib/groonga/record.rb groonga/trunk/test/test-database.rb groonga/trunk/test/test-expression.rb Modified: groonga/trunk/ext/rb-grn-table.c (+1 -3) =================================================================== --- groonga/trunk/ext/rb-grn-table.c 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/ext/rb-grn-table.c 2009-08-25 16:05:38 +09:00 (rev 637) @@ -1250,7 +1250,6 @@ grn_ctx *context; grn_obj *table, *result, *expression; grn_operator operator = GRN_OP_OR; - grn_rc rc; VALUE rb_query = Qnil, query_or_options, options; VALUE rb_name, rb_operator, rb_result; VALUE rb_expression, builder; @@ -1318,9 +1317,8 @@ } - rc = grn_table_select(context, table, expression, result, operator); + grn_table_select(context, table, expression, result, operator); rb_grn_context_check(context, self); - rb_grn_rc_check(rc, self); return rb_result; } Modified: groonga/trunk/ext/rb-grn-object.c (+4 -3) =================================================================== --- groonga/trunk/ext/rb-grn-object.c 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/ext/rb-grn-object.c 2009-08-25 16:05:38 +09:00 (rev 637) @@ -78,11 +78,12 @@ return rb_grn_object->object; } -grn_rc -rb_grn_object_finalizer (grn_ctx *context, grn_obj *grn_object, +static grn_obj * +rb_grn_object_finalizer (grn_ctx *context, int n_args, grn_obj **grn_objects, grn_user_data *user_data) { RbGrnObject *rb_grn_object; + grn_obj *grn_object = *grn_objects; rb_grn_object = user_data->ptr; @@ -137,7 +138,7 @@ break; } - return GRN_SUCCESS; + return NULL; } void Modified: groonga/trunk/ext/rb-grn-context.c (+10 -0) =================================================================== --- groonga/trunk/ext/rb-grn-context.c 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/ext/rb-grn-context.c 2009-08-25 16:05:38 +09:00 (rev 637) @@ -472,6 +472,14 @@ return GRNOBJECT2RVAL(Qnil, context, object, RB_GRN_FALSE); } +static VALUE +rb_grn_context_pop (VALUE self) +{ + grn_ctx *context; + context = SELF(self); + return GRNOBJ2RVAL(Qnil, context, grn_ctx_pop(context), self); +} + void rb_grn_init_context (VALUE mGrn) { @@ -500,4 +508,6 @@ rb_define_method(cGrnContext, "database", rb_grn_context_get_database, 0); rb_define_method(cGrnContext, "[]", rb_grn_context_array_reference, 1); + + rb_define_method(cGrnContext, "pop", rb_grn_context_pop, 0); } Modified: groonga/trunk/test/test-database.rb (+2 -0) =================================================================== --- groonga/trunk/test/test-database.rb 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/test/test-database.rb 2009-08-25 16:05:38 +09:00 (rev 637) @@ -88,6 +88,8 @@ "define_selector", "expr_missing", "load", + "now", + "rand", "select", "status", "table_create", Modified: groonga/trunk/ext/rb-grn-expression.c (+2 -2) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-25 16:05:38 +09:00 (rev 637) @@ -375,9 +375,9 @@ rb_define_method(rb_cGrnExpression, "define_variable", rb_grn_expression_define_variable, -1); rb_define_method(rb_cGrnExpression, "append_object", - rb_grn_expression_append_object, 1); + rb_grn_expression_append_object, -1); rb_define_method(rb_cGrnExpression, "append_constant", - rb_grn_expression_append_constant, 1); + rb_grn_expression_append_constant, -1); rb_define_method(rb_cGrnExpression, "append_operation", rb_grn_expression_append_operation, 2); Modified: groonga/trunk/lib/groonga/record.rb (+3 -1) =================================================================== --- groonga/trunk/lib/groonga/record.rb 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/lib/groonga/record.rb 2009-08-25 16:05:38 +09:00 (rev 637) @@ -119,7 +119,9 @@ private def column(name) - @table.column(name.to_s) + _column = @table.column(name.to_s) + raise InvalidArgument, "column(#{name.inspect}) is nil" if _column.nil? + _column end end end Modified: groonga/trunk/test/test-expression.rb (+8 -6) =================================================================== --- groonga/trunk/test/test-expression.rb 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/test/test-expression.rb 2009-08-25 16:05:38 +09:00 (rev 637) @@ -27,9 +27,10 @@ expression = Groonga::Expression.new expression.append_constant(morita) expression.append_constant("name") - expression.append_operation(Groonga::Operation::OBJECT_GET_VALUE, 2) + expression.append_operation(Groonga::Operation::GET_VALUE, 2) expression.compile - assert_equal("mori daijiro", expression.execute) + expression.execute + assert_equal("mori daijiro", context.pop) end def test_get_value_with_variable @@ -44,12 +45,13 @@ variable.value = morita expression.append_object(variable) expression.append_constant("name") - expression.append_operation(Groonga::Operation::OBJECT_GET_VALUE, 2) + expression.append_operation(Groonga::Operation::GET_VALUE, 2) expression.compile + expression.execute + assert_equal("mori daijiro", context.pop) - assert_equal("mori daijiro", expression.execute) - variable.value = gunyara_kun.id - assert_equal("Tasuku SUENAGA", expression.execute) + expression.execute + assert_equal("Tasuku SUENAGA", context.pop) end end Modified: groonga/trunk/ext/rb-grn-operation.c (+119 -22) =================================================================== --- groonga/trunk/ext/rb-grn-operation.c 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/ext/rb-grn-operation.c 2009-08-25 16:05:38 +09:00 (rev 637) @@ -25,40 +25,60 @@ { rb_mGrnOperation = rb_define_module_under(mGrn, "Operation"); - rb_define_const(rb_mGrnOperation, "NO_OPERATION", - UINT2NUM(GRN_OP_NOP)); rb_define_const(rb_mGrnOperation, "PUSH", UINT2NUM(GRN_OP_PUSH)); rb_define_const(rb_mGrnOperation, "POP", UINT2NUM(GRN_OP_POP)); + rb_define_const(rb_mGrnOperation, "NO_OPERATION", + UINT2NUM(GRN_OP_NOP)); rb_define_const(rb_mGrnOperation, "CALL", UINT2NUM(GRN_OP_CALL)); rb_define_const(rb_mGrnOperation, "INTERN", UINT2NUM(GRN_OP_INTERN)); - rb_define_const(rb_mGrnOperation, "TABLE_CREATE", - UINT2NUM(GRN_OP_TABLE_CREATE)); - rb_define_const(rb_mGrnOperation, "EXPRESSION_GET_VARIABLE", - UINT2NUM(GRN_OP_EXPR_GET_VAR)); - rb_define_const(rb_mGrnOperation, "VARIABLE_SET_VALUE", - UINT2NUM(GRN_OP_VAR_SET_VALUE)); - rb_define_const(rb_mGrnOperation, "OBJECT_GET_VALUE", - UINT2NUM(GRN_OP_OBJ_GET_VALUE)); - rb_define_const(rb_mGrnOperation, "OBJECT_SET_VALUE", - UINT2NUM(GRN_OP_OBJ_SET_VALUE)); - rb_define_const(rb_mGrnOperation, "OBJECT_SEARCH", - UINT2NUM(GRN_OP_OBJ_SEARCH)); - rb_define_const(rb_mGrnOperation, "TABLE_SELECT", - UINT2NUM(GRN_OP_TABLE_SELECT)); - rb_define_const(rb_mGrnOperation, "TABLE_SORT", - UINT2NUM(GRN_OP_TABLE_SORT)); - rb_define_const(rb_mGrnOperation, "TABLE_GROUP", - UINT2NUM(GRN_OP_TABLE_GROUP)); - rb_define_const(rb_mGrnOperation, "JSON_PUT", - UINT2NUM(GRN_OP_JSON_PUT)); + rb_define_const(rb_mGrnOperation, "GET_REFERENCE", + UINT2NUM(GRN_OP_GET_REF)); + rb_define_const(rb_mGrnOperation, "GET_VALUE", + UINT2NUM(GRN_OP_GET_VALUE)); rb_define_const(rb_mGrnOperation, "AND", UINT2NUM(GRN_OP_AND)); + rb_define_const(rb_mGrnOperation, "BUT", + UINT2NUM(GRN_OP_BUT)); rb_define_const(rb_mGrnOperation, "OR", UINT2NUM(GRN_OP_OR)); + rb_define_const(rb_mGrnOperation, "ASSIGN", + UINT2NUM(GRN_OP_ASSIGN)); + rb_define_const(rb_mGrnOperation, "STAR_ASSIGN", + UINT2NUM(GRN_OP_STAR_ASSIGN)); + rb_define_const(rb_mGrnOperation, "SLASH_ASSIGN", + UINT2NUM(GRN_OP_SLASH_ASSIGN)); + rb_define_const(rb_mGrnOperation, "MODULO_ASSIGN", + UINT2NUM(GRN_OP_MOD_ASSIGN)); + rb_define_const(rb_mGrnOperation, "PLUS_ASSIGN", + UINT2NUM(GRN_OP_PLUS_ASSIGN)); + rb_define_const(rb_mGrnOperation, "MINUS_ASSIGN", + UINT2NUM(GRN_OP_MINUS_ASSIGN)); + rb_define_const(rb_mGrnOperation, "SHIFTL_ASSIGN", + UINT2NUM(GRN_OP_SHIFTL_ASSIGN)); + rb_define_const(rb_mGrnOperation, "SHIRTR_ASSIGN", + UINT2NUM(GRN_OP_SHIRTR_ASSIGN)); + rb_define_const(rb_mGrnOperation, "SHIFTRR_ASSIGN", + UINT2NUM(GRN_OP_SHIFTRR_ASSIGN)); + rb_define_const(rb_mGrnOperation, "AND_ASSIGN", + UINT2NUM(GRN_OP_AND_ASSIGN)); + rb_define_const(rb_mGrnOperation, "XOR_ASSIGN", + UINT2NUM(GRN_OP_XOR_ASSIGN)); + rb_define_const(rb_mGrnOperation, "OR_ASSIGN", + UINT2NUM(GRN_OP_OR_ASSIGN)); + rb_define_const(rb_mGrnOperation, "QUESTION", + UINT2NUM(GRN_OP_QUESTION)); + rb_define_const(rb_mGrnOperation, "COLON", + UINT2NUM(GRN_OP_COLON)); + rb_define_const(rb_mGrnOperation, "BITWISE_OR", + UINT2NUM(GRN_OP_BITWISE_OR)); + rb_define_const(rb_mGrnOperation, "BITWISE_XOR", + UINT2NUM(GRN_OP_BITWISE_XOR)); + rb_define_const(rb_mGrnOperation, "BITWISE_AND", + UINT2NUM(GRN_OP_BITWISE_AND)); rb_define_const(rb_mGrnOperation, "EQUAL", UINT2NUM(GRN_OP_EQUAL)); rb_define_const(rb_mGrnOperation, "NOT_EQUAL", @@ -71,8 +91,85 @@ UINT2NUM(GRN_OP_LESS_EQUAL)); rb_define_const(rb_mGrnOperation, "GREATER_EQUAL", UINT2NUM(GRN_OP_GREATER_EQUAL)); + rb_define_const(rb_mGrnOperation, "IN", + UINT2NUM(GRN_OP_IN)); rb_define_const(rb_mGrnOperation, "MATCH", UINT2NUM(GRN_OP_MATCH)); + rb_define_const(rb_mGrnOperation, "NEAR", + UINT2NUM(GRN_OP_NEAR)); + rb_define_const(rb_mGrnOperation, "NEAR2", + UINT2NUM(GRN_OP_NEAR2)); + rb_define_const(rb_mGrnOperation, "SIMILAR", + UINT2NUM(GRN_OP_SIMILAR)); + rb_define_const(rb_mGrnOperation, "TERM_EXTRACT", + UINT2NUM(GRN_OP_TERM_EXTRACT)); + rb_define_const(rb_mGrnOperation, "SHIFTL", + UINT2NUM(GRN_OP_SHIFTL)); + rb_define_const(rb_mGrnOperation, "SHIFTR", + UINT2NUM(GRN_OP_SHIFTR)); + rb_define_const(rb_mGrnOperation, "SHIFTRR", + UINT2NUM(GRN_OP_SHIFTRR)); + rb_define_const(rb_mGrnOperation, "PLUS", + UINT2NUM(GRN_OP_PLUS)); + rb_define_const(rb_mGrnOperation, "MINUS", + UINT2NUM(GRN_OP_MINUS)); + rb_define_const(rb_mGrnOperation, "STAR", + UINT2NUM(GRN_OP_STAR)); + rb_define_const(rb_mGrnOperation, "SLASH", + UINT2NUM(GRN_OP_SLASH)); + rb_define_const(rb_mGrnOperation, "MODULO", + UINT2NUM(GRN_OP_MOD)); + rb_define_const(rb_mGrnOperation, "DELETE", + UINT2NUM(GRN_OP_DELETE)); + rb_define_const(rb_mGrnOperation, "INCREMENT", + UINT2NUM(GRN_OP_INCR)); + rb_define_const(rb_mGrnOperation, "DECREMENT", + UINT2NUM(GRN_OP_DECR)); + rb_define_const(rb_mGrnOperation, "NOT", + UINT2NUM(GRN_OP_NOT)); + rb_define_const(rb_mGrnOperation, "ADJUST", + UINT2NUM(GRN_OP_ADJUST)); + rb_define_const(rb_mGrnOperation, "EXACT", + UINT2NUM(GRN_OP_EXACT)); + rb_define_const(rb_mGrnOperation, "LONGEST_COMMON_PREFIX", + UINT2NUM(GRN_OP_LCP)); + rb_define_const(rb_mGrnOperation, "PARTIAL", + UINT2NUM(GRN_OP_PARTIAL)); + rb_define_const(rb_mGrnOperation, "UNSPLIT", + UINT2NUM(GRN_OP_UNSPLIT)); + rb_define_const(rb_mGrnOperation, "PREFIX", + UINT2NUM(GRN_OP_PREFIX)); + rb_define_const(rb_mGrnOperation, "SUFFIX", + UINT2NUM(GRN_OP_SUFFIX)); + rb_define_const(rb_mGrnOperation, "GEO_DISTANCE1", + UINT2NUM(GRN_OP_GEO_DISTANCE1)); + rb_define_const(rb_mGrnOperation, "GEO_DISTANCE2", + UINT2NUM(GRN_OP_GEO_DISTANCE2)); + rb_define_const(rb_mGrnOperation, "GEO_DISTANCE3", + UINT2NUM(GRN_OP_GEO_DISTANCE3)); + rb_define_const(rb_mGrnOperation, "GEO_DISTANCE4", + UINT2NUM(GRN_OP_GEO_DISTANCE4)); + rb_define_const(rb_mGrnOperation, "GEO_WITHINP5", + UINT2NUM(GRN_OP_GEO_WITHINP5)); + rb_define_const(rb_mGrnOperation, "GEO_WITHINP6", + UINT2NUM(GRN_OP_GEO_WITHINP6)); + rb_define_const(rb_mGrnOperation, "GEO_WITHINP8", + UINT2NUM(GRN_OP_GEO_WITHINP8)); + rb_define_const(rb_mGrnOperation, "OBJECT_SEARCH", + UINT2NUM(GRN_OP_OBJ_SEARCH)); + rb_define_const(rb_mGrnOperation, "EXPRESSION_GET_VARIABLE", + UINT2NUM(GRN_OP_EXPR_GET_VAR)); + rb_define_const(rb_mGrnOperation, "TABLE_CREATE", + UINT2NUM(GRN_OP_TABLE_CREATE)); + rb_define_const(rb_mGrnOperation, "TABLE_SELECT", + UINT2NUM(GRN_OP_TABLE_SELECT)); + rb_define_const(rb_mGrnOperation, "TABLE_SORT", + UINT2NUM(GRN_OP_TABLE_SORT)); + rb_define_const(rb_mGrnOperation, "TABLE_GROUP", + UINT2NUM(GRN_OP_TABLE_GROUP)); + rb_define_const(rb_mGrnOperation, "JSON_PUT", + UINT2NUM(GRN_OP_JSON_PUT)); + /* rb_define_const(rb_mGrnOperation, "GEO_DISTANCE1", UINT2NUM(GRN_OP_GEO_DISTANCE1)); Modified: groonga/trunk/lib/groonga/expression-builder.rb (+1 -1) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-25 15:54:57 +09:00 (rev 636) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-25 16:05:38 +09:00 (rev 637) @@ -99,7 +99,7 @@ def build(expression, variable) expression.append_object(variable) expression.append_constant(@column_name) - expression.append_operation(Groonga::Operation::OBJECT_GET_VALUE, 2) + expression.append_operation(Groonga::Operation::GET_VALUE, 2) expression.append_constant(@value) expression.append_operation(@operation, 2) end From null at cozmixng.org Tue Aug 25 03:35:37 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Tue, 25 Aug 2009 16:35:37 +0900 Subject: [groonga-commit:602] groonga [groonga (trunk) r638] follow the recent groonga changes Message-ID: <20090825073538.2029A1D1C9C@mail.cozmixng.org> retro 2009-08-25 16:35:37 +0900 (Tue, 25 Aug 2009) New Revision: 638 Log: follow the recent groonga changes Modified files: groonga/trunk/ext/rb-grn-utils.c groonga/trunk/test/test-table.rb Modified: groonga/trunk/ext/rb-grn-utils.c (+8 -2) =================================================================== --- groonga/trunk/ext/rb-grn-utils.c 2009-08-25 15:57:53 +09:00 (rev 637) +++ groonga/trunk/ext/rb-grn-utils.c 2009-08-25 16:35:37 +09:00 (rev 638) @@ -217,8 +217,14 @@ break; case T_BIGNUM: int64_value = NUM2LL(object); - string = (const char *)&int64_value; - size = sizeof(int64_value); + if (int64_value <= INT32_MAX) { + int32_value = int64_value; + string = (const char *)&int32_value; + size = sizeof(int32_value); + } else { + string = (const char *)&int64_value; + size = sizeof(int64_value); + } break; case T_FLOAT: double_value = NUM2DBL(object); Modified: groonga/trunk/test/test-table.rb (+1 -3) =================================================================== --- groonga/trunk/test/test-table.rb 2009-08-25 15:57:53 +09:00 (rev 637) +++ groonga/trunk/test/test-table.rb 2009-08-25 16:35:37 +09:00 (rev 638) @@ -154,9 +154,7 @@ table_path = @tables_dir + "bookmarks" table = Groonga::Hash.create(:name => "bookmarks", :path => table_path.to_s) - assert_raise(Groonga::InvalidArgument) do - table.column("nonexistent") - end + assert_nil(table.column("nonexistent")) end def test_set_value From null at cozmixng.org Wed Aug 26 20:35:26 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 09:35:26 +0900 Subject: [groonga-commit:603] groonga [groonga (trunk) r639] follow the recent changes of grn_operator Message-ID: <20090827003526.CDB4E1D1C82@mail.cozmixng.org> retro 2009-08-27 09:35:26 +0900 (Thu, 27 Aug 2009) New Revision: 639 Log: follow the recent changes of grn_operator Modified files: groonga/trunk/ext/rb-grn-operation.c Modified: groonga/trunk/ext/rb-grn-operation.c (+11 -4) =================================================================== --- groonga/trunk/ext/rb-grn-operation.c 2009-08-25 16:26:47 +09:00 (rev 638) +++ groonga/trunk/ext/rb-grn-operation.c 2009-08-27 09:35:26 +09:00 (rev 639) @@ -69,16 +69,18 @@ UINT2NUM(GRN_OP_XOR_ASSIGN)); rb_define_const(rb_mGrnOperation, "OR_ASSIGN", UINT2NUM(GRN_OP_OR_ASSIGN)); - rb_define_const(rb_mGrnOperation, "QUESTION", - UINT2NUM(GRN_OP_QUESTION)); - rb_define_const(rb_mGrnOperation, "COLON", - UINT2NUM(GRN_OP_COLON)); + rb_define_const(rb_mGrnOperation, "TERNARY", + UINT2NUM(GRN_OP_TERNARY)); + rb_define_const(rb_mGrnOperation, "COMMA", + UINT2NUM(GRN_OP_COMMA)); rb_define_const(rb_mGrnOperation, "BITWISE_OR", UINT2NUM(GRN_OP_BITWISE_OR)); rb_define_const(rb_mGrnOperation, "BITWISE_XOR", UINT2NUM(GRN_OP_BITWISE_XOR)); rb_define_const(rb_mGrnOperation, "BITWISE_AND", UINT2NUM(GRN_OP_BITWISE_AND)); + rb_define_const(rb_mGrnOperation, "BITWISE_NOT", + UINT2NUM(GRN_OP_BITWISE_NOT)); rb_define_const(rb_mGrnOperation, "EQUAL", UINT2NUM(GRN_OP_EQUAL)); rb_define_const(rb_mGrnOperation, "NOT_EQUAL", @@ -125,6 +127,10 @@ UINT2NUM(GRN_OP_INCR)); rb_define_const(rb_mGrnOperation, "DECREMENT", UINT2NUM(GRN_OP_DECR)); + rb_define_const(rb_mGrnOperation, "INCREMENT_POST", + UINT2NUM(GRN_OP_INCR_POST)); + rb_define_const(rb_mGrnOperation, "DECREMENT_POST", + UINT2NUM(GRN_OP_DECR_POST)); rb_define_const(rb_mGrnOperation, "NOT", UINT2NUM(GRN_OP_NOT)); rb_define_const(rb_mGrnOperation, "ADJUST", @@ -170,6 +176,7 @@ rb_define_const(rb_mGrnOperation, "JSON_PUT", UINT2NUM(GRN_OP_JSON_PUT)); + /* rb_define_const(rb_mGrnOperation, "GEO_DISTANCE1", UINT2NUM(GRN_OP_GEO_DISTANCE1)); From null at cozmixng.org Wed Aug 26 22:05:27 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 11:05:27 +0900 Subject: [groonga-commit:604] groonga [groonga (trunk) r640] add an test for Expression#inspect Message-ID: <20090827020527.855F11D1CBF@mail.cozmixng.org> retro 2009-08-27 11:05:27 +0900 (Thu, 27 Aug 2009) New Revision: 640 Log: add an test for Expression#inspect Modified files: groonga/trunk/test/test-expression.rb Modified: groonga/trunk/test/test-expression.rb (+10 -0) =================================================================== --- groonga/trunk/test/test-expression.rb 2009-08-27 09:20:57 +09:00 (rev 639) +++ groonga/trunk/test/test-expression.rb 2009-08-27 11:05:27 +09:00 (rev 640) @@ -54,4 +54,14 @@ expression.execute assert_equal("Tasuku SUENAGA", context.pop) end + + def test_inspect + expression = Groonga::Expression.new + expression.append_constant(1) + expression.append_constant(1) + expression.append_operation(Groonga::Operation::PLUS, 2) + expression.compile + + assert_equal("#", expression.inspect) + end end From null at cozmixng.org Thu Aug 27 00:05:25 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 13:05:25 +0900 Subject: [groonga-commit:605] groonga [groonga (trunk) r641] test/test-table-select.rb: tests of select extracted from Message-ID: <20090827040525.D0FC71D1C80@mail.cozmixng.org> retro 2009-08-27 13:05:25 +0900 (Thu, 27 Aug 2009) New Revision: 641 Log: test/test-table-select.rb: tests of select extracted from test/test-table.rb lib/groonga/expression-builder.rb, ext/rb-grn-table.c: 'build' supports combination of a query string and a block Added files: groonga/trunk/test/test-table-select.rb Modified files: groonga/trunk/ext/rb-grn-table.c groonga/trunk/lib/groonga/expression-builder.rb groonga/trunk/test/test-table.rb Modified: groonga/trunk/ext/rb-grn-table.c (+7 -25) =================================================================== --- groonga/trunk/ext/rb-grn-table.c 2009-08-27 11:02:36 +09:00 (rev 640) +++ groonga/trunk/ext/rb-grn-table.c 2009-08-27 13:05:25 +09:00 (rev 641) @@ -1261,11 +1261,6 @@ NULL, NULL, NULL); if (RVAL2CBOOL(rb_obj_is_kind_of(query_or_options, rb_cString))) { - if (rb_block_given_p()) - rb_raise(rb_eArgError, - "should not specify both of query string and " - "expression block: %s", - rb_grn_inspect(rb_ary_new4(argc, argv))); rb_query = query_or_options; } else { if (!NIL_P(options)) @@ -1295,28 +1290,15 @@ result = RVAL2GRNTABLE(rb_result, &context); } - if (NIL_P(rb_query)) { - builder = rb_grn_record_expression_builder_new(self, rb_name); - rb_expression = rb_grn_record_expression_builder_build(builder); - rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)), - &expression, NULL, + builder = rb_grn_record_expression_builder_new(self, rb_name); + if (!NIL_P(rb_query)) { + rb_funcall(builder, rb_intern("query="), 1, rb_query); + } + rb_expression = rb_grn_record_expression_builder_build(builder); + rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)), + &expression, NULL, NULL, NULL, NULL, NULL); - } else { - const char *name = NULL, *query; - unsigned name_size = 0, query_size; - query = StringValueCStr(rb_query); - query_size = RSTRING_LEN(rb_query); - if (!NIL_P(rb_name)) { - name = StringValueCStr(rb_name); - name_size = RSTRING_LEN(rb_name); - } - expression = grn_expr_create_from_str(context, name, name_size, - query, query_size, - table, NULL); - } - - grn_table_select(context, table, expression, result, operator); rb_grn_context_check(context, self); Added: groonga/trunk/test/test-table-select.rb (+92 -0) =================================================================== --- groonga/trunk/test/test-table-select.rb 2009-08-27 11:02:36 +09:00 (rev 640) +++ groonga/trunk/test/test-table-select.rb 2009-08-27 13:05:25 +09:00 (rev 641) @@ -0,0 +1,92 @@ +# Copyright (C) 2009 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 TableTestSelect < Test::Unit::TestCase + include GroongaTestUtils + + setup :setup_database + + def test_select_sub_expression + comments = Groonga::Array.create(:name => "comments") + comments.define_column("content", "Text") + comments.define_column("created_at", "Time") + terms = Groonga::PatriciaTrie.create(:name => "terms") + terms.define_index_column("comment_content", comments, + :with_section => true, + :source => "comments.content") + comment1 = comments.add(:content => "Hello Good-bye!", + :created_at => Time.parse("2009-08-09")) + comment2 = comments.add(:content => "Hello World", + :created_at => Time.parse("2009-07-09")) + comment3 = comments.add(:content => "test", + :created_at => Time.parse("2009-06-09")) + result = comments.select do |record| + record.match("Hello", "content") & + (record["created_at"] < Time.parse("2009-08-01")) + end + assert_equal([comment2], + result.collect {|record| record.key}) + end + + def test_select_query + comments = Groonga::Array.create(:name => "comments") + comments.define_column("content", "Text") + comments.define_column("created_at", "Time") + terms = Groonga::PatriciaTrie.create(:name => "terms") + terms.define_index_column("comment_content", comments, + :with_section => true, + :source => "comments.content") + comment1 = comments.add(:content => "Hello Good-bye!", + :created_at => Time.parse("2009-08-09")) + comment2 = comments.add(:content => "Hello World", + :created_at => Time.parse("2009-07-09")) + comment3 = comments.add(:content => "test", + :created_at => Time.parse("2009-06-09")) + result = comments.select("content:%Hello") + assert_equal([comment1, comment2], result.collect {|record| record.key}) + end + + priority :must + def test_select_query_with_block + comments = Groonga::Array.create(:name => "comments") + comments.define_column("content", "Text") + comments.define_column("created_at", "Time") + terms = Groonga::PatriciaTrie.create(:name => "terms") + terms.define_index_column("comment_content", comments, + :with_section => true, + :source => "comments.content") + comment1 = comments.add(:content => "Hello Good-bye!", + :created_at => Time.parse("2009-08-09")) + comment2 = comments.add(:content => "Hello World", + :created_at => Time.parse("2009-07-09")) + comment3 = comments.add(:content => "test", + :created_at => Time.parse("2009-06-09")) + + result = comments.select("content:%Hello") do |record| + record["created_at"] < Time.parse("2009-08-01") + end + + assert_equal([comment2], result.collect {|record| record.key}) + end + + def test_select_without_block + comments = Groonga::Array.create(:name => "comments") + comment1 = comments.add + comment2 = comments.add + comment3 = comments.add + assert_equal([comment1, comment2, comment3], + comments.select.collect {|record| record.key}) + end +end Modified: groonga/trunk/test/test-table.rb (+0 -31) =================================================================== --- groonga/trunk/test/test-table.rb 2009-08-27 11:02:36 +09:00 (rev 640) +++ groonga/trunk/test/test-table.rb 2009-08-27 13:05:25 +09:00 (rev 641) @@ -382,37 +382,6 @@ results.collect {|record| record["id"]}) end - def test_select_sub_expression - comments = Groonga::Array.create(:name => "comments") - comments.define_column("content", "Text") - comments.define_column("created_at", "Time") - terms = Groonga::PatriciaTrie.create(:name => "terms") - terms.define_index_column("comment_content", comments, - :with_section => true, - :source => "comments.content") - comment1 = comments.add(:content => "Hello Good-bye!", - :created_at => Time.parse("2009-08-09")) - comment2 = comments.add(:content => "Hello World", - :created_at => Time.parse("2009-07-09")) - comment3 = comments.add(:content => "test", - :created_at => Time.parse("2009-06-09")) - result = comments.select do |record| - record.match("Hello", "content") & - (record["created_at"] < Time.parse("2009-08-01")) - end - assert_equal([comment2], - result.collect {|record| record.key}) - end - - def test_select_without_block - comments = Groonga::Array.create(:name => "comments") - comment1 = comments.add - comment2 = comments.add - comment3 = comments.add - assert_equal([comment1, comment2, comment3], - comments.select.collect {|record| record.key}) - end - def test_group bookmarks = Groonga::Hash.create(:name => "") bookmarks.define_column("title", "") Modified: groonga/trunk/lib/groonga/expression-builder.rb (+10 -2) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 11:02:36 +09:00 (rev 640) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 13:05:25 +09:00 (rev 641) @@ -18,6 +18,8 @@ module Groonga module ExpressionBuildable attr_reader :table + attr_accessor :query + def initialize(*args) @table = nil @name = nil @@ -28,12 +30,18 @@ def build expression = Expression.new(:table => @table, :name => @name, - :query => @query, :default_column => @default_column) variable = expression.define_variable(:domain => @table) builder = nil - builder = yield(self) if block_given? + builder = self.match(@query) if @query + if block_given? + if builder + builder &= yield(self) + else + builder = yield(self) + end + end if builder.nil? or builder == self expression.append_constant(1) expression.append_constant(1) From null at cozmixng.org Thu Aug 27 00:21:14 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 13:21:14 +0900 Subject: [groonga-commit:606] groonga [groonga (trunk) r642] test/test-table-select.rb: clean up Message-ID: <20090827042114.961A21D1C80@mail.cozmixng.org> retro 2009-08-27 13:21:13 +0900 (Thu, 27 Aug 2009) New Revision: 642 Log: test/test-table-select.rb: clean up Modified files: groonga/trunk/test/test-table-select.rb Modified: groonga/trunk/test/test-table-select.rb (+23 -51) =================================================================== --- groonga/trunk/test/test-table-select.rb 2009-08-27 12:58:41 +09:00 (rev 641) +++ groonga/trunk/test/test-table-select.rb 2009-08-27 13:21:13 +09:00 (rev 642) @@ -18,75 +18,47 @@ setup :setup_database - def test_select_sub_expression - comments = Groonga::Array.create(:name => "comments") - comments.define_column("content", "Text") - comments.define_column("created_at", "Time") + setup + def setup_comments + @comments = Groonga::Array.create(:name => "comments") + @comments.define_column("content", "Text") + @comments.define_column("created_at", "Time") terms = Groonga::PatriciaTrie.create(:name => "terms") - terms.define_index_column("comment_content", comments, + terms.define_index_column("comment_content", @comments, :with_section => true, :source => "comments.content") - comment1 = comments.add(:content => "Hello Good-bye!", - :created_at => Time.parse("2009-08-09")) - comment2 = comments.add(:content => "Hello World", - :created_at => Time.parse("2009-07-09")) - comment3 = comments.add(:content => "test", - :created_at => Time.parse("2009-06-09")) - result = comments.select do |record| + @comment1 = @comments.add(:content => "Hello Good-bye!", + :created_at => Time.parse("2009-08-09")) + @comment2 = @comments.add(:content => "Hello World", + :created_at => Time.parse("2009-07-09")) + @comment3 = @comments.add(:content => "test", + :created_at => Time.parse("2009-06-09")) + end + + def test_select_sub_expression + result = @comments.select do |record| record.match("Hello", "content") & (record["created_at"] < Time.parse("2009-08-01")) end - assert_equal([comment2], + assert_equal([@comment2], result.collect {|record| record.key}) end def test_select_query - comments = Groonga::Array.create(:name => "comments") - comments.define_column("content", "Text") - comments.define_column("created_at", "Time") - terms = Groonga::PatriciaTrie.create(:name => "terms") - terms.define_index_column("comment_content", comments, - :with_section => true, - :source => "comments.content") - comment1 = comments.add(:content => "Hello Good-bye!", - :created_at => Time.parse("2009-08-09")) - comment2 = comments.add(:content => "Hello World", - :created_at => Time.parse("2009-07-09")) - comment3 = comments.add(:content => "test", - :created_at => Time.parse("2009-06-09")) - result = comments.select("content:%Hello") - assert_equal([comment1, comment2], result.collect {|record| record.key}) + result = @comments.select("content:%Hello") + assert_equal([@comment1, @comment2], result.collect {|record| record.key}) end priority :must def test_select_query_with_block - comments = Groonga::Array.create(:name => "comments") - comments.define_column("content", "Text") - comments.define_column("created_at", "Time") - terms = Groonga::PatriciaTrie.create(:name => "terms") - terms.define_index_column("comment_content", comments, - :with_section => true, - :source => "comments.content") - comment1 = comments.add(:content => "Hello Good-bye!", - :created_at => Time.parse("2009-08-09")) - comment2 = comments.add(:content => "Hello World", - :created_at => Time.parse("2009-07-09")) - comment3 = comments.add(:content => "test", - :created_at => Time.parse("2009-06-09")) - - 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([comment2], result.collect {|record| record.key}) + assert_equal([@comment2], result.collect {|record| record.key}) end def test_select_without_block - comments = Groonga::Array.create(:name => "comments") - comment1 = comments.add - comment2 = comments.add - comment3 = comments.add - assert_equal([comment1, comment2, comment3], - comments.select.collect {|record| record.key}) + assert_equal([@comment1, @comment2, @comment3], + @comments.select.collect {|record| record.key}) end end From null at cozmixng.org Thu Aug 27 00:21:17 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 13:21:17 +0900 Subject: [groonga-commit:607] groonga [groonga (trunk) r643] test/test-table-select.rb: add test of match query and match block Message-ID: <20090827042117.BA1441D1CBF@mail.cozmixng.org> retro 2009-08-27 13:21:16 +0900 (Thu, 27 Aug 2009) New Revision: 643 Log: test/test-table-select.rb: add test of match query and match block Modified files: groonga/trunk/test/test-table-select.rb Modified: groonga/trunk/test/test-table-select.rb (+7 -0) =================================================================== --- groonga/trunk/test/test-table-select.rb 2009-08-27 13:06:50 +09:00 (rev 642) +++ groonga/trunk/test/test-table-select.rb 2009-08-27 13:21:16 +09:00 (rev 643) @@ -57,6 +57,13 @@ assert_equal([@comment2], result.collect {|record| record.key}) end + def test_select_query_with_block_match + result = @comments.select("content:%Hello") do |record| + record.match("World", "content") + end + assert_equal([@comment2], result.collect {|record| record.key}) + end + def test_select_without_block assert_equal([@comment1, @comment2, @comment3], @comments.select.collect {|record| record.key}) From null at cozmixng.org Thu Aug 27 02:05:39 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 15:05:39 +0900 Subject: [groonga-commit:608] groonga [groonga (trunk) r644] removed parameters query, table and default_column from Expression#new Message-ID: <20090827060539.93ECC1D1C82@mail.cozmixng.org> retro 2009-08-27 15:05:39 +0900 (Thu, 27 Aug 2009) New Revision: 644 Log: removed parameters query, table and default_column from Expression#new Modified files: groonga/trunk/lib/groonga/expression-builder.rb Modified: groonga/trunk/lib/groonga/expression-builder.rb (+1 -3) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 13:10:23 +09:00 (rev 643) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 15:05:39 +09:00 (rev 644) @@ -28,9 +28,7 @@ end def build - expression = Expression.new(:table => @table, - :name => @name, - :default_column => @default_column) + expression = Expression.new(:name => @name) variable = expression.define_variable(:domain => @table) builder = nil From null at cozmixng.org Thu Aug 27 02:20:51 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 15:20:51 +0900 Subject: [groonga-commit:609] groonga [groonga (trunk) r645] removed use of create_from_str Message-ID: <20090827062051.C21B81D1C82@mail.cozmixng.org> retro 2009-08-27 15:20:51 +0900 (Thu, 27 Aug 2009) New Revision: 645 Log: removed use of create_from_str Modified files: groonga/trunk/ext/rb-grn-expression.c Modified: groonga/trunk/ext/rb-grn-expression.c (+4 -23) =================================================================== --- groonga/trunk/ext/rb-grn-expression.c 2009-08-27 14:59:02 +09:00 (rev 644) +++ groonga/trunk/ext/rb-grn-expression.c 2009-08-27 15:20:51 +09:00 (rev 645) @@ -70,17 +70,14 @@ { grn_ctx *context = NULL; grn_obj *expression; - VALUE options, rb_context, rb_name, rb_query, rb_table, rb_default_column; - char *name = NULL, *query = NULL; - unsigned name_size = 0, query_size = 0; + VALUE options, rb_context, rb_name; + char *name = NULL; + unsigned name_size = 0; rb_scan_args(argc, argv, "01", &options); rb_grn_scan_options(options, "context", &rb_context, "name", &rb_name, - "query", &rb_query, - "table", &rb_table, - "default_column", &rb_default_column, NULL); context = rb_grn_context_ensure(&rb_context); @@ -90,23 +87,7 @@ name_size = RSTRING_LEN(rb_name); } - if (!NIL_P(rb_query)) { - query = StringValuePtr(rb_query); - query_size = RSTRING_LEN(rb_query); - } - - if (query) { - grn_obj *table; - grn_obj *default_column = NULL; - - table = RVAL2GRNOBJECT(rb_table, &context); - default_column = RVAL2GRNBULK(rb_default_column, context, default_column); - expression = grn_expr_create_from_str(context, name, name_size, - query, query_size, - table, default_column); - } else { - expression = grn_expr_create(context, name, name_size); - } + expression = grn_expr_create(context, name, name_size); rb_grn_object_assign(Qnil, self, rb_context, context, expression); rb_grn_context_check(context, self); From null at cozmixng.org Thu Aug 27 02:20:53 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 15:20:53 +0900 Subject: [groonga-commit:610] groonga [groonga (trunk) r646] add test_select to test-column.rb Message-ID: <20090827062054.062091D1C83@mail.cozmixng.org> retro 2009-08-27 15:20:52 +0900 (Thu, 27 Aug 2009) New Revision: 646 Log: add test_select to test-column.rb Modified files: groonga/trunk/test/test-column.rb Modified: groonga/trunk/test/test-column.rb (+22 -0) =================================================================== --- groonga/trunk/test/test-column.rb 2009-08-27 15:11:18 +09:00 (rev 645) +++ groonga/trunk/test/test-column.rb 2009-08-27 15:20:52 +09:00 (rev 646) @@ -174,6 +174,28 @@ assert_equal("title", title.local_name) end + def test_select + posts = Groonga::Hash.create(:name => "", :key_type => "") + body = posts.define_column("body", "") + + index = Groonga::PatriciaTrie.create(:name => "", + :key_type => "", + :key_normalize => true) + index.default_tokenizer = "" + body_index = index.define_index_column("body_index", posts, + :with_position => true, + :source => body) + + first_post = posts.add("Hello!", :body => "World") + hobby = posts.add("My Hobby", :body => "Drive and Eat") + + result = body.select("drive") + assert_equal(["Drive and Eat"], + result.records.collect do |record| + record["body"] + end) + end + private def assert_content_search(expected_records, term) records = @bookmarks_index_content.search(term).records From null at cozmixng.org Thu Aug 27 02:50:28 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 15:50:28 +0900 Subject: [groonga-commit:611] groonga [groonga (trunk) r647] use column_expression_builder instead of create_from_str Message-ID: <20090827065028.710D81D1C83@mail.cozmixng.org> retro 2009-08-27 15:50:28 +0900 (Thu, 27 Aug 2009) New Revision: 647 Log: use column_expression_builder instead of create_from_str Modified files: groonga/trunk/ext/rb-grn-column.c groonga/trunk/lib/groonga/expression-builder.rb Modified: groonga/trunk/ext/rb-grn-column.c (+8 -3) =================================================================== --- groonga/trunk/ext/rb-grn-column.c 2009-08-27 15:12:27 +09:00 (rev 646) +++ groonga/trunk/ext/rb-grn-column.c 2009-08-27 15:50:28 +09:00 (rev 647) @@ -171,6 +171,8 @@ VALUE rb_query, rb_name, rb_operator, rb_result; char *name = NULL, *query; unsigned name_size = 0, query_size; + VALUE builder; + VALUE rb_expression; rb_scan_args(argc, argv, "11", &rb_query, &options); @@ -206,9 +208,12 @@ result = RVAL2GRNTABLE(rb_result, &context); } - expression = grn_expr_create_from_str(context, name, name_size, - query, query_size, - table, column); + builder = rb_grn_column_expression_builder_new(self, rb_name, rb_query); + rb_expression = rb_grn_column_expression_builder_build(builder); + rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)), + &expression, NULL, + NULL, NULL, NULL, NULL); + grn_table_select(context, table, expression, result, operator); rb_grn_context_check(context, self); Modified: groonga/trunk/lib/groonga/expression-builder.rb (+11 -7) =================================================================== --- groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 15:12:27 +09:00 (rev 646) +++ groonga/trunk/lib/groonga/expression-builder.rb 2009-08-27 15:50:28 +09:00 (rev 647) @@ -32,7 +32,7 @@ variable = expression.define_variable(:domain => @table) builder = nil - builder = self.match(@query) if @query + builder = match(@query) if @query if block_given? if builder builder &= yield(self) @@ -203,29 +203,33 @@ end def ==(other) - EqualExpressionBuilder.new(@column.local_name, normalize(other)) + EqualExpressionBuilder.new(@default_column, normalize(other)) end def =~(other) - MatchExpressionBuilder.new(@column.local_name, normalize(other)) + MatchExpressionBuilder.new(@default_column, normalize(other)) end def <(other) - LessExpressionBuilder.new(@column.local_name, normalize(other)) + LessExpressionBuilder.new(@default_column, normalize(other)) end def <=(other) - LessEqualExpressionBuilder.new(@column.local_name, normalize(other)) + LessEqualExpressionBuilder.new(@default_column, normalize(other)) end def >(other) - GreaterExpressionBuilder.new(@column.local_name, normalize(other)) + GreaterExpressionBuilder.new(@default_column, normalize(other)) end def >=(other) - GreaterEqualExpressionBuilder.new(@column.local_name, normalize(other)) + GreaterEqualExpressionBuilder.new(@default_column, normalize(other)) end + def match(query) + SubExpressionBuilder.new(query, :default_column => @default_column) + end + private def normalize(other) if @range.is_a?(Groonga::Table) and other.is_a?(Integer) From null at cozmixng.org Thu Aug 27 02:50:29 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 15:50:29 +0900 Subject: [groonga-commit:612] groonga [groonga (trunk) r648] column_select: query is optional Message-ID: <20090827065029.CB8831D1CAF@mail.cozmixng.org> retro 2009-08-27 15:50:29 +0900 (Thu, 27 Aug 2009) New Revision: 648 Log: column_select: query is optional Modified files: groonga/trunk/ext/rb-grn-column.c groonga/trunk/test/test-column.rb Modified: groonga/trunk/ext/rb-grn-column.c (+15 -12) =================================================================== --- groonga/trunk/ext/rb-grn-column.c 2009-08-27 15:36:16 +09:00 (rev 647) +++ groonga/trunk/ext/rb-grn-column.c 2009-08-27 15:50:29 +09:00 (rev 648) @@ -168,33 +168,36 @@ grn_obj *table, *column, *result, *expression; grn_operator operator = GRN_OP_OR; VALUE options; - VALUE rb_query, rb_name, rb_operator, rb_result; - char *name = NULL, *query; - unsigned name_size = 0, query_size; + VALUE rb_query, rb_query_or_options, rb_name, rb_operator, rb_result; VALUE builder; VALUE rb_expression; + + rb_query = Qnil; - rb_scan_args(argc, argv, "11", &rb_query, &options); + rb_scan_args(argc, argv, "02", &rb_query_or_options, &options); - query = StringValueCStr(rb_query); - query_size = RSTRING_LEN(rb_query); - rb_grn_column_deconstruct(SELF(self), &column, &context, NULL, NULL, NULL, NULL, NULL); table = grn_column_table(context, column); + if (RVAL2CBOOL(rb_obj_is_kind_of(rb_query_or_options, rb_cString))) { + rb_query = rb_query_or_options; + } else { + if (!NIL_P(options)) + rb_raise(rb_eArgError, + "should be [query_string, option_hash] " + "or [option_hash]: %s", + rb_grn_inspect(rb_ary_new4(argc, argv))); + options = rb_query_or_options; + } + rb_grn_scan_options(options, "operator", &rb_operator, "result", &rb_result, "name", &rb_name, NULL); - if (!NIL_P(rb_name)) { - name = StringValueCStr(rb_name); - name_size = RSTRING_LEN(rb_name); - } - if (!NIL_P(rb_operator)) operator = NUM2INT(rb_operator); Modified: groonga/trunk/test/test-column.rb (+24 -0) =================================================================== --- groonga/trunk/test/test-column.rb 2009-08-27 15:36:16 +09:00 (rev 647) +++ groonga/trunk/test/test-column.rb 2009-08-27 15:50:29 +09:00 (rev 648) @@ -196,6 +196,30 @@ end) end + def test_select_with_block + posts = Groonga::Hash.create(:name => "", :key_type => "") + body = posts.define_column("body", "") + + index = Groonga::PatriciaTrie.create(:name => "", + :key_type => "", + :key_normalize => true) + index.default_tokenizer = "" + body_index = index.define_index_column("body_index", posts, + :with_position => true, + :source => body) + + first_post = posts.add("Hello!", :body => "World") + hobby = posts.add("My Hobby", :body => "Drive and Eat") + + result = body.select do |column| + column =~ "drive" + end + assert_equal(["Drive and Eat"], + result.records.collect do |record| + record["body"] + end) + end + private def assert_content_search(expected_records, term) records = @bookmarks_index_content.search(term).records From null at cozmixng.org Thu Aug 27 05:50:30 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 18:50:30 +0900 Subject: [groonga-commit:613] groonga [groonga (trunk) r650] ext/rb-grn-utils.c (rb_grn_bulk_from_ruby_object): use rb_grn_bulk_from_ruby_object_with_type if GRN_DB_TIME Message-ID: <20090827095030.6F20C1D1CC8@mail.cozmixng.org> retro 2009-08-27 18:50:30 +0900 (Thu, 27 Aug 2009) New Revision: 650 Log: ext/rb-grn-utils.c (rb_grn_bulk_from_ruby_object): use rb_grn_bulk_from_ruby_object_with_type if GRN_DB_TIME (rb_grn_bulk_from_ruby_object_with_type): accept Integer as UNIX time on coercing to GRN_DB_TIME. Modified files: groonga/trunk/example/bookmark.rb groonga/trunk/ext/rb-grn-utils.c Modified: groonga/trunk/example/bookmark.rb (+1 -1) =================================================================== --- groonga/trunk/example/bookmark.rb 2009-08-27 18:42:57 +09:00 (rev 649) +++ groonga/trunk/example/bookmark.rb 2009-08-27 18:50:30 +09:00 (rev 650) @@ -107,7 +107,7 @@ "????", "taporobo", "???? Scheme LISP", 1187568793) p add_bookmark("http://practical-scheme.net/docs/cont-j.html", "??????", "taporobo", "?????? LISP continuation", - 1187568692) + 1187568692.98765) p add_bookmark("http://jp.rubyist.net/managinze", "???", "moritan", "Ruby ??????", Time.now) Modified: groonga/trunk/ext/rb-grn-utils.c (+31 -7) =================================================================== --- groonga/trunk/ext/rb-grn-utils.c 2009-08-27 18:42:57 +09:00 (rev 649) +++ groonga/trunk/ext/rb-grn-utils.c 2009-08-27 18:50:30 +09:00 (rev 650) @@ -200,6 +200,11 @@ grn_id id_value; grn_obj_flags flags = 0; + if (bulk && bulk->header.domain == GRN_DB_TIME) + return rb_grn_bulk_from_ruby_object_with_type( + object, context, bulk, bulk->header.domain, + grn_ctx_at(context, bulk->header.domain)); + switch (TYPE(object)) { case T_NIL: string = NULL; @@ -282,7 +287,7 @@ int64_t time_value; double double_value; grn_id range; - VALUE rb_type; + VALUE rb_type_object; grn_obj_flags flags = 0; switch (type_id) { @@ -308,11 +313,30 @@ break; case GRN_DB_TIME: { - VALUE sec, usec; + VALUE rb_sec, rb_usec; + int64_t sec; + int32_t usec; - sec = rb_funcall(object, rb_intern("to_i"), 0); - usec = rb_funcall(object, rb_intern("usec"), 0); - time_value = NUM2LL(sec) * RB_GRN_USEC_PER_SEC + NUM2LL(usec); + switch (TYPE(object)) { + case T_FIXNUM: + case T_BIGNUM: + sec = NUM2LL(object); + usec = 0; + break; + case T_FLOAT: + rb_sec = rb_funcall(object, rb_intern("to_i"), 0); + rb_usec = rb_funcall(object, rb_intern("remainder"), 1, INT2NUM(1)); + + sec = NUM2LL(rb_sec); + usec = (int32_t)(NUM2DBL(rb_usec) * 1000000); + break; + default: + sec = NUM2LL(rb_funcall(object, rb_intern("to_i"), 0)); + usec = NUM2INT(rb_funcall(object, rb_intern("usec"), 0)); + break; + } + + time_value = sec * RB_GRN_USEC_PER_SEC + usec; } string = (const char *)&time_value; size = sizeof(time_value); @@ -335,10 +359,10 @@ case GRN_DB_BIGRAM: case GRN_DB_TRIGRAM: case GRN_DB_MECAB: - rb_type = GRNOBJECT2RVAL(Qnil, context, type, RB_GRN_FALSE); + rb_type_object = GRNOBJECT2RVAL(Qnil, context, type, RB_GRN_FALSE); rb_raise(rb_eArgError, "unbulkable type: %s", - rb_grn_inspect(rb_type)); + rb_grn_inspect(rb_type_object)); break; default: return RVAL2GRNBULK(object, context, bulk); From null at cozmixng.org Thu Aug 27 05:50:29 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Thu, 27 Aug 2009 18:50:29 +0900 Subject: [groonga-commit:614] groonga [groonga (trunk) r649] fixed bugs in codes of a tutorial Message-ID: <20090827095029.148A01D1C74@mail.cozmixng.org> retro 2009-08-27 18:50:28 +0900 (Thu, 27 Aug 2009) New Revision: 649 Log: fixed bugs in codes of a tutorial Modified files: groonga/trunk/TUTORIAL.ja.rdoc Modified: groonga/trunk/TUTORIAL.ja.rdoc (+3 -6) =================================================================== --- groonga/trunk/TUTORIAL.ja.rdoc 2009-08-27 15:47:47 +09:00 (rev 648) +++ groonga/trunk/TUTORIAL.ja.rdoc 2009-08-27 18:50:28 +09:00 (rev 649) @@ -53,7 +53,7 @@ ?????????????????????????? ????????? - >> items = Groonga::Hash.create(:name => "", :persistent => true) + >> items = Groonga::Hash.create(:name => "") => # @@ -93,7 +93,7 @@ ???????+title+???????????????? - >> title_column = items.define_column("title", "", :persistent => true) + >> title_column = items.define_column("title", "") => # 2??????????????????????????? @@ -106,7 +106,6 @@ >> terms = Groonga::Hash.create(:name => "", :key_type => "", - :persistent => true, :default_tokenizer => "") => # @@ -126,7 +125,6 @@ ??+title+???????????????????? >> title_index_column = terms.define_index_column("item_title", items, - :persistent => true, :source => ".title") => # @@ -187,8 +185,7 @@ ?????????????? - >> comments = Groonga::Array.create(:name => "", - :key_type => "") + >> comments = Groonga::Array.create(:name => "") => # >> comments.define_column("item", items) => # From null at cozmixng.org Thu Aug 27 11:20:36 2009 From: null at cozmixng.org (null at cozmixng.org) Date: Fri, 28 Aug 2009 00:20:36 +0900 Subject: [groonga-commit:615] groonga [groonga (trunk) r651] test/test-column.rb: add tests of coercing (Integer|Float) to Time Message-ID: <20090827152037.055211D1C74@mail.cozmixng.org> retro 2009-08-28 00:20:36 +0900 (Fri, 28 Aug 2009) New Revision: 651 Log: test/test-column.rb: add tests of coercing (Integer|Float) to Time Modified files: groonga/trunk/test/test-column.rb Modified: groonga/trunk/test/test-column.rb (+12 -0) =================================================================== --- groonga/trunk/test/test-column.rb 2009-08-27 18:47:13 +09:00 (rev 650) +++ groonga/trunk/test/test-column.rb 2009-08-28 00:20:36 -15:00 (rev 651) @@ -220,6 +220,18 @@ end) end + def test_set_time + posts = Groonga::Hash.create(:name => "", :key_type => "") + body = posts.define_column("issued", "