rroonga 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/AUTHORS +5 -0
  2. data/Gemfile +1 -12
  3. data/Rakefile +4 -57
  4. data/bin/grndump +11 -1
  5. data/ext/groonga/extconf.rb +125 -54
  6. data/ext/groonga/rb-grn-context.c +25 -7
  7. data/ext/groonga/rb-grn-database.c +25 -0
  8. data/ext/groonga/rb-grn-object.c +19 -7
  9. data/ext/groonga/rb-grn-table.c +8 -10
  10. data/ext/groonga/rb-grn.h +9 -2
  11. data/lib/groonga/dumper.rb +2 -2
  12. data/lib/groonga/expression-builder.rb +33 -18
  13. data/rroonga-build.rb +1 -1
  14. metadata +97 -180
  15. data/TODO +0 -0
  16. data/test/groonga-test-utils.rb +0 -139
  17. data/test/run-test.rb +0 -60
  18. data/test/test-accessor.rb +0 -36
  19. data/test/test-array.rb +0 -123
  20. data/test/test-column.rb +0 -350
  21. data/test/test-command-select.rb +0 -147
  22. data/test/test-context.rb +0 -130
  23. data/test/test-database-dumper.rb +0 -259
  24. data/test/test-database.rb +0 -148
  25. data/test/test-double-array-trie.rb +0 -164
  26. data/test/test-encoding.rb +0 -33
  27. data/test/test-exception.rb +0 -96
  28. data/test/test-expression-builder.rb +0 -269
  29. data/test/test-expression.rb +0 -134
  30. data/test/test-fix-size-column.rb +0 -77
  31. data/test/test-gqtp.rb +0 -70
  32. data/test/test-hash.rb +0 -344
  33. data/test/test-index-column.rb +0 -180
  34. data/test/test-index-cursor.rb +0 -93
  35. data/test/test-logger.rb +0 -37
  36. data/test/test-pagination.rb +0 -249
  37. data/test/test-patricia-trie.rb +0 -415
  38. data/test/test-plugin.rb +0 -35
  39. data/test/test-procedure.rb +0 -37
  40. data/test/test-query-log.rb +0 -258
  41. data/test/test-record.rb +0 -569
  42. data/test/test-remote.rb +0 -63
  43. data/test/test-schema-create-table.rb +0 -267
  44. data/test/test-schema-dumper.rb +0 -235
  45. data/test/test-schema-type.rb +0 -208
  46. data/test/test-schema-view.rb +0 -90
  47. data/test/test-schema.rb +0 -886
  48. data/test/test-snippet.rb +0 -130
  49. data/test/test-table-cursor.rb +0 -187
  50. data/test/test-table-dumper.rb +0 -83
  51. data/test/test-table-offset-and-limit.rb +0 -100
  52. data/test/test-table-select-mecab.rb +0 -80
  53. data/test/test-table-select-normalize.rb +0 -57
  54. data/test/test-table-select-weight.rb +0 -123
  55. data/test/test-table-select.rb +0 -191
  56. data/test/test-table.rb +0 -675
  57. data/test/test-type.rb +0 -79
  58. data/test/test-variable-size-column.rb +0 -147
  59. data/test/test-variable.rb +0 -28
  60. data/test/test-vector-column.rb +0 -76
  61. data/test/test-version.rb +0 -61
  62. data/test/test-view.rb +0 -72
data/TODO DELETED
File without changes
@@ -1,139 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- require 'fileutils'
17
- require 'pathname'
18
- require 'time'
19
- require 'erb'
20
- require 'stringio'
21
- require 'json'
22
- require 'pkg-config'
23
-
24
- require 'groonga'
25
-
26
- module GroongaTestUtils
27
- class << self
28
- def included(base)
29
- base.setup :setup_sandbox, :before => :prepend
30
- base.teardown :teardown_sandbox, :after => :append
31
- end
32
- end
33
-
34
- def setup_sandbox
35
- setup_tmp_directory
36
- setup_log_path
37
-
38
- setup_tables_directory
39
- setup_columns_directory
40
-
41
- setup_encoding
42
- setup_context
43
- end
44
-
45
- def setup_tmp_directory
46
- @tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
47
- FileUtils.rm_rf(@tmp_dir.to_s)
48
- FileUtils.mkdir_p(@tmp_dir.to_s)
49
- end
50
-
51
- def setup_log_path
52
- @dump_log = false
53
- Groonga::Logger.log_path = (@tmp_dir + "groonga.log").to_s
54
- Groonga::Logger.query_log_path = (@tmp_dir + "groonga-query.log").to_s
55
- end
56
-
57
- def setup_tables_directory
58
- @tables_dir = @tmp_dir + "tables"
59
- FileUtils.mkdir_p(@tables_dir.to_s)
60
- end
61
-
62
- def setup_columns_directory
63
- @columns_dir = @tmp_dir + "columns"
64
- FileUtils.mkdir_p(@columns_dir.to_s)
65
- end
66
-
67
- def setup_encoding
68
- Groonga::Encoding.default = nil
69
- end
70
-
71
- def setup_context
72
- Groonga::Context.default = nil
73
- Groonga::Context.default_options = nil
74
- end
75
-
76
- def context
77
- Groonga::Context.default
78
- end
79
-
80
- def encoding
81
- Groonga::Encoding.default
82
- end
83
-
84
- def setup_logger
85
- Groonga::Logger.register(:level => :dump) do |level, time, title, message, location|
86
- p [level, time, title, message, location]
87
- end
88
- end
89
-
90
- def setup_database
91
- @database_path = @tmp_dir + "database"
92
- @database = Groonga::Database.create(:path => @database_path.to_s)
93
- end
94
-
95
- def teardown_sandbox
96
- @database = nil
97
- GC.start
98
- teardown_log_path
99
- teardown_tmp_directory
100
- end
101
-
102
- def teardown_log_path
103
- return unless @dump_log
104
- log_path = Groonga::Logger.log_path
105
- query_log_path = Groonga::Logger.query_log_path
106
- if File.exist?(log_path)
107
- header = "--- log: #{log_path} ---"
108
- puts(header)
109
- puts(File.read(log_path))
110
- puts("-" * header.length)
111
- end
112
- if File.exist?(query_log_path)
113
- header = "--- query log: #{query_log_path} ---"
114
- puts(header)
115
- puts(File.read(query_log_path))
116
- puts("-" * header.length)
117
- end
118
- end
119
-
120
- def teardown_tmp_directory
121
- FileUtils.rm_rf(@tmp_dir.to_s)
122
- end
123
-
124
- private
125
- def assert_equal_select_result(expected, actual, &normalizer)
126
- normalizer ||= Proc.new {|record| record.key}
127
- assert_equal(expected,
128
- actual.collect(&normalizer),
129
- actual.expression.inspect)
130
- end
131
-
132
- def ruby19?
133
- RUBY_VERSION >= "1.9"
134
- end
135
-
136
- def only_ruby19
137
- omit("Ruby 1.9 is needed.") unless ruby19?
138
- end
139
- end
data/test/run-test.rb DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- $VERBOSE = true
19
-
20
- $KCODE = "u" if RUBY_VERSION < "1.9"
21
-
22
- base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
23
- ext_dir = File.join(base_dir, "ext", "groonga")
24
- lib_dir = File.join(base_dir, "lib")
25
- test_dir = File.join(base_dir, "test")
26
-
27
- make = nil
28
- if ENV["NO_MAKE"] != "yes"
29
- if system("which gmake > /dev/null")
30
- make = "gmake"
31
- elsif system("which make > /dev/null")
32
- make = "make"
33
- end
34
- end
35
- if make
36
- system("cd #{base_dir.dump} && #{make} > /dev/null") or exit(false)
37
- end
38
-
39
- require "test-unit"
40
- require "test/unit/notify"
41
-
42
- Test::Unit::Priority.enable
43
-
44
- $LOAD_PATH.unshift(ext_dir)
45
- $LOAD_PATH.unshift(lib_dir)
46
- $LOAD_PATH.unshift(base_dir)
47
-
48
- $LOAD_PATH.unshift(test_dir)
49
- require 'groonga-test-utils'
50
-
51
- pkg_config = File.join(base_dir, "vendor", "local", "lib", "pkgconfig")
52
- PKGConfig.add_path(pkg_config)
53
-
54
- Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
55
- require file.sub(/\.rb$/, '')
56
- end
57
-
58
- ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000"
59
-
60
- exit Test::Unit::AutoRunner.run
@@ -1,36 +0,0 @@
1
- # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- class AccessorTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- setup_database
21
- @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
22
- @id = @posts.column("_id")
23
- end
24
-
25
- def teardown
26
- @id = nil
27
- end
28
-
29
- def test_name
30
- assert_nil(@id.name)
31
- end
32
-
33
- def test_local_name
34
- assert_equal("_id", @id.local_name)
35
- end
36
- end
data/test/test-array.rb DELETED
@@ -1,123 +0,0 @@
1
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- class ArrayTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
-
21
- def test_support_key?
22
- assert_not_predicate(Groonga::Array.create(:name => "Users"), :support_key?)
23
- end
24
-
25
- def test_inspect_size
26
- path = @tables_dir + "named.groonga"
27
- contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
28
- 3.times do
29
- contain_table.add
30
- end
31
- assert_equal("#<Groonga::Array " +
32
- "id: <#{contain_table.id}>, " +
33
- "name: <name>, " +
34
- "path: <#{path}>, " +
35
- "domain: (nil), " +
36
- "range: (nil), " +
37
- "flags: <>, " +
38
- "size: <3>>",
39
- contain_table.inspect)
40
- end
41
-
42
- def test_encoding
43
- array = Groonga::Array.create
44
- assert_false(array.respond_to?(:encoding))
45
- end
46
-
47
- def test_add
48
- users = Groonga::Array.create(:name => "Users")
49
- users.define_column("name", "Text")
50
- me = users.add(:name => "me")
51
- assert_equal("me", me[:name])
52
- end
53
-
54
- def test_define_index_column
55
- users = Groonga::Array.create(:name => "Users")
56
- users.define_column("name", "Text")
57
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
58
- bookmarks.define_column("title", "Text")
59
- bookmarks.define_column("user", users)
60
-
61
- index = users.define_index_column("bookmarks", bookmarks,
62
- :source => "Bookmarks.user")
63
- morita = users.add(:name => "morita")
64
- gunyara_kun = users.add(:name => "gunyara-kun")
65
- bookmarks.add(:title => "groonga", :user => morita)
66
- bookmarks.add(:title => "google", :user => morita)
67
- bookmarks.add(:title => "Python", :user => gunyara_kun)
68
-
69
- assert_equal(["groonga", "google"],
70
- index.search(morita.id).collect {|record| record.key["title"]})
71
- end
72
-
73
- def test_create_duplicated_name
74
- Groonga::Array.create(:name => "Users")
75
- assert_raise(Groonga::InvalidArgument) do
76
- Groonga::Array.create(:name => "Users")
77
- end
78
- end
79
-
80
- def test_value
81
- users = Groonga::Array.create(:value_type => "Int32")
82
- user_id = users.add.id
83
- users.set_value(user_id, 29)
84
- assert_equal(29, users.value(user_id))
85
- end
86
-
87
- def test_column_value
88
- users = Groonga::Array.create(:name => "Users")
89
- users.define_column("name", "ShortText")
90
- morita_id = users.add.id
91
- users.set_column_value(morita_id, "name", "morita")
92
- assert_equal("morita", users.column_value(morita_id, "name"))
93
- end
94
-
95
- def test_added?
96
- users = Groonga::Array.create(:name => "Users")
97
- first_user = users.add
98
- assert_predicate(first_user, :added?)
99
- second_user = users.add
100
- assert_predicate(second_user, :added?)
101
- end
102
-
103
- def test_defrag
104
- users = Groonga::Array.create(:name => "Users")
105
- users.define_column("name", "ShortText")
106
- users.define_column("address", "ShortText")
107
- 1000.times do |i|
108
- users.add(:name => "user #{i}" * 1000,
109
- :address => "address #{i}" * 1000)
110
- end
111
- assert_equal(7, users.defrag)
112
- end
113
-
114
- def test_rename
115
- users = Groonga::Array.create(:name => "Users")
116
- name = users.define_column("name", "ShortText")
117
- address = users.define_column("address", "ShortText")
118
-
119
- users.rename("People")
120
- assert_equal(["People", "People.name", "People.address"],
121
- [users.name, name.name, address.name])
122
- end
123
- end
data/test/test-column.rb DELETED
@@ -1,350 +0,0 @@
1
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- class ColumnTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- setup_database
21
-
22
- setup_users_table
23
- setup_bookmarks_table
24
- setup_indexes
25
- end
26
-
27
- def setup_users_table
28
- @users_path = @tables_dir + "users"
29
- @users = Groonga::Array.create(:name => "Users",
30
- :path => @users_path.to_s)
31
-
32
- @users_name_column_path = @columns_dir + "name"
33
- @users_name_column =
34
- @users.define_column("name", "ShortText",
35
- :path => @users_name_column_path.to_s)
36
- end
37
-
38
- def setup_bookmarks_table
39
- @bookmarks_path = @tables_dir + "bookmarks"
40
- @bookmarks = Groonga::Array.create(:name => "Bookmarks",
41
- :path => @bookmarks_path.to_s)
42
-
43
- @uri_column_path = @columns_dir + "uri"
44
- @bookmarks_uri = @bookmarks.define_column("uri", "ShortText",
45
- :path => @uri_column_path.to_s)
46
-
47
- @comment_column_path = @columns_dir + "comment"
48
- @bookmarks_comment =
49
- @bookmarks.define_column("comment", "Text",
50
- :path => @comment_column_path.to_s)
51
-
52
- @content_column_path = @columns_dir + "content"
53
- @bookmarks_content = @bookmarks.define_column("content", "LongText")
54
-
55
- @user_column_path = @columns_dir + "user"
56
- @bookmarks_user = @bookmarks.define_column("user", @users)
57
- end
58
-
59
- def setup_indexes
60
- @bookmarks_index_path = @tables_dir + "bookmarks-index"
61
- @bookmarks_index =
62
- Groonga::PatriciaTrie.create(:name => "BookmarksIndex",
63
- :path => @bookmarks_index_path.to_s,
64
- :key_type => "ShortText")
65
- @bookmarks_index.default_tokenizer = "TokenBigram"
66
-
67
- @content_index_column_path = @columns_dir + "content-index"
68
- @bookmarks_index_content =
69
- @bookmarks_index.define_index_column("content", @bookmarks,
70
- :with_section => true,
71
- :with_weight => true,
72
- :with_position => true,
73
- :path => @content_index_column_path.to_s)
74
-
75
- @uri_index_column_path = @columns_dir + "uri-index"
76
- @bookmarks_index_uri =
77
- @bookmarks_index.define_index_column("uri", @bookmarks,
78
- :path => @uri_index_column_path.to_s)
79
- end
80
-
81
- def test_source_info
82
- @bookmarks_index_content.sources = [@bookmarks_content]
83
-
84
- groonga = @bookmarks.add
85
- groonga["content"] = "<html><body>groonga</body></html>"
86
-
87
- ruby = @bookmarks.add
88
- ruby["content"] = "<html><body>ruby</body></html>"
89
-
90
- assert_content_search([groonga], "groonga")
91
- assert_content_search([groonga, ruby], "html")
92
-
93
- assert_equal([@bookmarks_content], @bookmarks_index_content.sources)
94
- end
95
-
96
- def test_update_index_column
97
- groonga = @bookmarks.add
98
- groonga["content"] = "<html><body>groonga</body></html>"
99
-
100
- ruby = @bookmarks.add
101
- ruby["content"] = "<html><body>ruby</body></html>"
102
-
103
- @bookmarks_index_content[groonga.id] = groonga["content"]
104
- @bookmarks_index_content[ruby.id] = ruby["content"]
105
-
106
- assert_content_search([groonga], "groonga")
107
- assert_content_search([groonga, ruby], "html")
108
- end
109
-
110
- def test_range
111
- assert_equal(context[Groonga::Type::SHORT_TEXT], @bookmarks_uri.range)
112
- assert_equal(context[Groonga::Type::TEXT], @bookmarks_comment.range)
113
- assert_equal(context[Groonga::Type::LONG_TEXT], @bookmarks_content.range)
114
- assert_equal(@users, @bookmarks_user.range)
115
- assert_equal(@bookmarks, @bookmarks_index_content.range)
116
- assert_equal(@bookmarks, @bookmarks_index_uri.range)
117
- end
118
-
119
- def test_accessor
120
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
121
- posts.define_column("body", "Text")
122
- comments = Groonga::Hash.create(:name => "Comments",
123
- :key_type => "ShortText")
124
- content = comments.define_column("content", "ShortText")
125
- comments.define_column("post", posts)
126
-
127
- index = Groonga::PatriciaTrie.create(:name => "Terms",
128
- :key_type => "ShortText")
129
- index.default_tokenizer = "TokenBigram"
130
- content_index = index.define_index_column("content_index", comments,
131
- :with_position => true)
132
- content_index.source = content
133
-
134
- first_post = posts.add("Hello!")
135
- first_post["body"] = "World"
136
- hobby = posts.add("My Hobby")
137
- hobby["body"] = "Drive and Eat"
138
-
139
- friend = comments.add("Me too")
140
- friend["content"] = "I'm also like drive"
141
- friend["post"] = hobby
142
-
143
- result = content_index.search("drive")
144
- assert_equal([["I'm also like drive", "My Hobby"]],
145
- result.records.collect do |record|
146
- [record[".content"], record[".post._key"]]
147
- end)
148
- end
149
-
150
- def test_accessor_reference
151
- bookmark = @bookmarks.add
152
- assert_nil(@bookmarks_user[bookmark.id])
153
-
154
- daijiro = @users.add
155
- daijiro["name"] = "daijiro"
156
- @bookmarks_user[bookmark.id] = daijiro
157
- assert_equal(daijiro, @bookmarks_user[bookmark.id])
158
- end
159
-
160
- def test_array_set_with_key_of_table
161
- languages = Groonga::Hash.create(:name => "Languages",
162
- :key_type => "ShortText")
163
- sites = Groonga::Hash.create(:name => "Sites")
164
- sites.define_column("language", languages)
165
-
166
- languages.add("Ruby")
167
- taiyaki_ru = sites.add("http://taiyaki.ru/", :language => "Ruby")
168
- assert_equal("Ruby", taiyaki_ru[:language].key)
169
- end
170
-
171
- def test_local_name
172
- items = Groonga::Array.create(:name => "Items")
173
- title = items.define_column("title", "ShortText")
174
- assert_equal("Items.title", title.name)
175
- assert_equal("title", title.local_name)
176
- end
177
-
178
- def test_select_query
179
- populate_table_for_select
180
-
181
- result = @body.select("drive")
182
- assert_equal(["Drive and Eat"],
183
- result.records.collect do |record|
184
- record["body"]
185
- end)
186
- assert_equal("#<Groonga::Expression noname($1:\"\")" +
187
- "{2body GET_VALUE,0\"drive\",0MATCH}>",
188
- result.expression.inspect)
189
- end
190
-
191
- def test_select_query_from_ctx
192
- populate_table_for_select
193
-
194
- body = Groonga::Context.default['Posts.body']
195
- # select twice.
196
- result = body.select("drive")
197
- assert_equal(["Drive and Eat"],
198
- result.records.collect do |record|
199
- record["body"]
200
- end)
201
-
202
- result = body.select("drive")
203
- assert_equal(["Drive and Eat"],
204
- result.records.collect do |record|
205
- record["body"]
206
- end)
207
- end
208
-
209
- def test_select_query_with_parser
210
- populate_table_for_select
211
-
212
- result = @body.select("body @ \"drive\"", :syntax => :script)
213
- assert_equal(["Drive and Eat"],
214
- result.records.collect do |record|
215
- record["body"]
216
- end)
217
- assert_equal("#<Groonga::Expression noname($1:\"\")" +
218
- "{2body GET_VALUE,0\"drive\",0MATCH}>",
219
- result.expression.inspect)
220
- end
221
-
222
- def test_select_expression
223
- populate_table_for_select
224
-
225
- expression = Groonga::Expression.new
226
- variable = expression.define_variable(:domain => @posts)
227
- expression.append_object(variable)
228
- expression.parse("body:@drive", :syntax => :query)
229
- expression.compile
230
- result = @body.select(expression)
231
- assert_equal(["Drive and Eat"],
232
- result.records.collect do |record|
233
- record["body"]
234
- end)
235
- assert_equal("#<Groonga::Expression noname($1:\"\")" +
236
- "{0\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
237
- result.expression.inspect)
238
- end
239
-
240
- def test_select_with_block
241
- populate_table_for_select
242
-
243
- result = @body.select do |column|
244
- column =~ "drive"
245
- end
246
- assert_equal(["Drive and Eat"],
247
- result.records.collect do |record|
248
- record["body"]
249
- end)
250
- assert_equal("#<Groonga::Expression noname($1:\"\")" +
251
- "{1\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
252
- result.expression.inspect)
253
- end
254
-
255
- def test_set_time
256
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
257
- posts.define_column("issued", "Time")
258
-
259
- post = posts.add("hello", :issued => 123456)
260
- assert_equal(Time.at(123456), post[".issued"])
261
- post = posts.add("groonga", :issued => 1251380635)
262
- assert_equal(Time.parse("2009-08-27 22:43:55"), post[".issued"])
263
- post = posts.add("mroonga", :issued => 1251380635.1234567)
264
- assert_in_delta(Time.at(1251380635.1234567).usec, post[".issued"].usec, 10)
265
- end
266
-
267
- def test_set_nil_to_time
268
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
269
- posts.define_column("issued", "Time")
270
-
271
- post = posts.add("hello", :issued => nil)
272
- assert_equal(Time.at(0), post["issued"])
273
- end
274
-
275
- def test_bool
276
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
277
- posts.define_column("hidden", "Bool")
278
-
279
- post = posts.add("hello")
280
- assert_false(post["hidden"])
281
-
282
- post["hidden"] = true
283
- assert_true(post["hidden"])
284
-
285
- post["hidden"] = false
286
- assert_false(post["hidden"])
287
- end
288
-
289
- def test_indexes
290
- Groonga::Schema.define do |schema|
291
- schema.create_table("Comments") do |table|
292
- table.short_text("title")
293
- end
294
- end
295
- title = Groonga["Comments.title"]
296
- assert_equal([], title.indexes)
297
-
298
- Groonga::Schema.define do |schema|
299
- schema.create_table("Terms",
300
- :type => :patricia_trie,
301
- :default_tokenizer => "TokenBigram") do |table|
302
- table.index("Comments.title")
303
- end
304
- end
305
- assert_equal([Groonga["Terms.Comments_title"]],
306
- title.indexes)
307
-
308
- Groonga::Schema.define do |schema|
309
- schema.create_table("Titles",
310
- :type => :hash) do |table|
311
- table.index("Comments.title")
312
- end
313
- end
314
- assert_equal([Groonga["Titles.Comments_title"],
315
- Groonga["Terms.Comments_title"]],
316
- title.indexes)
317
- end
318
-
319
- def test_builtin?
320
- assert_not_predicate(@users_name_column, :builtin?)
321
- end
322
-
323
- private
324
- def assert_content_search(expected_records, term)
325
- records = @bookmarks_index_content.search(term).records
326
- expected_contents = expected_records.collect do |record|
327
- record["content"]
328
- end
329
- actual_contents = records.collect do |record|
330
- record.key["content"]
331
- end
332
- assert_equal(expected_contents, actual_contents)
333
- end
334
-
335
- def populate_table_for_select
336
- @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
337
- @body = @posts.define_column("body", "Text")
338
-
339
- index = Groonga::PatriciaTrie.create(:name => "Terms",
340
- :key_type => "ShortText",
341
- :key_normalize => true)
342
- index.default_tokenizer = "TokenBigram"
343
- index.define_index_column("body_index", @posts,
344
- :with_position => true,
345
- :source => @body)
346
-
347
- @posts.add("Hello!", :body => "World")
348
- @posts.add("My Hobby", :body => "Drive and Eat")
349
- end
350
- end