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/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ Kouhei Sutou <kou@clear-code.com>
2
+ Tasuku SUENAGA <a@razil.jp>
3
+ daijiro <morita@razil.jp>
4
+ Yuto HAYAMIZU <y.hayamizu@gmail.com>
5
+ SHIDARA Yoji <dara@shidara.net>
data/Gemfile CHANGED
@@ -17,15 +17,4 @@
17
17
 
18
18
  source "http://rubygems.org/"
19
19
 
20
- gem 'pkg-config'
21
- gem 'json'
22
-
23
- group :development, :test do
24
- gem "test-unit", ">= 2.4.6"
25
- gem "test-unit-notify"
26
- gem "rake"
27
- gem "rake-compiler"
28
- gem "jeweler"
29
- gem "yard"
30
- gem "packnga"
31
- end
20
+ gemspec
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ require 'erb'
24
24
  require 'rubygems'
25
25
  require 'rubygems/package_task'
26
26
  require 'yard'
27
- require 'jeweler'
27
+ require 'bundler/gem_helper'
28
28
  require 'rake/extensiontask'
29
29
  require 'packnga'
30
30
 
@@ -43,62 +43,9 @@ $LOAD_PATH.unshift(groonga_ext_dir)
43
43
  $LOAD_PATH.unshift(groonga_lib_dir)
44
44
  ENV["RUBYLIB"] = "#{groonga_lib_dir}:#{groonga_ext_dir}:#{ENV['RUBYLIB']}"
45
45
 
46
- def guess_version(groonga_ext_dir)
47
- version = {}
48
- File.open(File.join(groonga_ext_dir, "rb-grn.h")) do |rb_grn_h|
49
- rb_grn_h.each_line do |line|
50
- case line
51
- when /\A#define RB_GRN_([A-Z]+)_VERSION (\d+)/
52
- version[$1.downcase] = $2
53
- end
54
- end
55
- end
56
- [version["major"], version["minor"], version["micro"]].join(".")
57
- end
58
-
59
- def cleanup_white_space(entry)
60
- entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
61
- end
62
-
63
- ENV["VERSION"] ||= guess_version(groonga_ext_dir)
64
- version = ENV["VERSION"].dup
65
- spec = nil
66
- Jeweler::Tasks.new do |_spec|
67
- spec = _spec
68
- spec.name = "rroonga"
69
- spec.version = version
70
- spec.rubyforge_project = "groonga"
71
- spec.homepage = "http://groonga.rubyforge.org/"
72
- authors = File.join(base_dir, "AUTHORS")
73
- spec.authors = File.readlines(authors).collect do |line|
74
- if /\s*<[^<>]*>$/ =~ line
75
- $PREMATCH
76
- else
77
- nil
78
- end
79
- end.compact
80
- spec.email = [
81
- 'groonga-users-en@rubyforge.org',
82
- 'groonga-dev@lists.sourceforge.jp',
83
- ]
84
- entries = File.read("README.textile").split(/^h2\.\s(.*)$/)
85
- description = cleanup_white_space(entries[entries.index("Description") + 1])
86
- spec.summary, spec.description, = description.split(/\n\n+/, 3)
87
- spec.license = "LGPLv2"
88
- spec.files = FileList["{lib,benchmark,misc}/**/*.rb",
89
- "bin/*",
90
- "extconf.rb",
91
- "rroonga-build.rb",
92
- "example/*.rb",
93
- "Rakefile",
94
- "Gemfile",
95
- "ext/**/*.{c,h,rb,def}"]
96
- spec.test_files = FileList["test/**/*.rb"]
97
- end
98
-
99
- Rake::Task["release"].prerequisites.clear
100
- Jeweler::RubygemsDotOrgTasks.new do
101
- end
46
+ helper = Bundler::GemHelper.new(base_dir)
47
+ helper.install
48
+ spec = helper.gemspec
102
49
 
103
50
  Gem::PackageTask.new(spec) do |pkg|
104
51
  pkg.need_tar_gz = true
data/bin/grndump CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
  #
4
- # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
@@ -27,6 +27,7 @@ options.tables = []
27
27
  options.exclude_tables = []
28
28
  options.dump_schema = true
29
29
  options.dump_tables = true
30
+ options.order_by = "id"
30
31
  option_parser = OptionParser.new do |parser|
31
32
  parser.banner += " DB_PATH"
32
33
 
@@ -63,6 +64,14 @@ option_parser = OptionParser.new do |parser|
63
64
  options.exclude_tables << table
64
65
  end
65
66
  end
67
+
68
+ types = ["id", "key"]
69
+ parser.on("--order-by=TYPE", types,
70
+ "sort output recoreds by TYPE.",
71
+ "available TYPEs: #{types.join(', ')}",
72
+ "(#{options.type})") do |type|
73
+ options.order_by = type
74
+ end
66
75
  end
67
76
  args = option_parser.parse!(ARGV)
68
77
 
@@ -80,6 +89,7 @@ dumper_options = {
80
89
  :dump_tables => options.dump_tables,
81
90
  :tables => options.tables,
82
91
  :exclude_tables => options.exclude_tables,
92
+ :order_by => options.order_by,
83
93
  }
84
94
  database_dumper = Groonga::DatabaseDumper.new(dumper_options)
85
95
  database_dumper.dump
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -15,21 +15,24 @@
15
15
  # License along with this library; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
 
18
- require 'English'
19
- require 'pathname'
20
- require 'mkmf'
18
+ require "English"
19
+ require "pathname"
20
+ require "mkmf"
21
+ require "fileutils"
22
+ require "shellwords"
23
+ require "open-uri"
21
24
 
22
25
  begin
23
- require 'pkg-config'
26
+ require "pkg-config"
24
27
  rescue LoadError
25
- require 'rubygems'
26
- require 'pkg-config'
28
+ require "rubygems"
29
+ require "pkg-config"
27
30
  end
28
31
 
29
- base_dir = Pathname(__FILE__).dirname.parent.parent
32
+ base_dir = Pathname(__FILE__).dirname.parent.parent.expand_path
30
33
  $LOAD_PATH.unshift(base_dir.to_s)
31
34
 
32
- require 'rroonga-build'
35
+ require "rroonga-build"
33
36
 
34
37
  include RroongaBuild
35
38
 
@@ -39,15 +42,19 @@ major, minor, micro = RequiredGroongaVersion::VERSION
39
42
 
40
43
  checking_for(checking_message("GCC")) do
41
44
  if macro_defined?("__GNUC__", "")
42
- $CFLAGS += ' -Wall'
45
+ $CFLAGS += " -Wall"
43
46
  true
44
47
  else
45
48
  false
46
49
  end
47
50
  end
48
51
 
52
+ def win32?
53
+ /cygwin|mingw|mswin/ =~ RUBY_PLATFORM
54
+ end
55
+
49
56
  checking_for(checking_message("Win32 OS")) do
50
- win32 = /cygwin|mingw|mswin/ =~ RUBY_PLATFORM
57
+ win32 = win32?
51
58
  if win32
52
59
  $defs << "-DRB_GRN_PLATFORM_WIN32"
53
60
  import_library_name = "libruby-#{module_name}.a"
@@ -62,68 +69,132 @@ checking_for(checking_message("Win32 OS")) do
62
69
  end
63
70
 
64
71
  def install_groonga_locally(major, minor, micro)
65
- require 'open-uri'
66
- require 'shellwords'
67
-
68
- tar_gz = "groonga-#{major}.#{minor}.#{micro}.tar.gz"
69
72
  FileUtils.mkdir_p(local_groonga_base_dir)
70
73
 
71
- install_dir = local_groonga_install_dir
72
74
  Dir.chdir(local_groonga_base_dir) do
73
- url = "http://packages.groonga.org/source/groonga/#{tar_gz}"
74
- message("downloading %s...", url)
75
+ if win32?
76
+ extract_groonga_win32_binary(major, minor, micro)
77
+ else
78
+ build_groonga(major, minor, micro)
79
+ end
80
+ end
81
+
82
+ prepend_pkg_config_path_for_local_groonga
83
+ end
84
+
85
+ def download(url)
86
+ message("downloading %s...", url)
87
+ base_name = File.basename(url)
88
+ if File.exist?(base_name)
89
+ message(" skip (use downloaded file)\n")
90
+ else
75
91
  open(url, "rb") do |input|
76
- File.open(tar_gz, "wb") do |output|
92
+ File.open(base_name, "wb") do |output|
77
93
  while (buffer = input.read(1024))
78
94
  output.print(buffer)
79
95
  end
80
96
  end
81
97
  end
82
98
  message(" done\n")
99
+ end
100
+ end
101
+
102
+ def extract_zip(filename, destrination_dir)
103
+ begin
104
+ require "archive/zip"
105
+ rescue LoadError
106
+ require "rubygems"
107
+ require "archive/zip"
108
+ end
109
+
110
+ Archive::Zip.extract(filename, destrination_dir)
111
+ end
112
+
113
+ def extract_groonga_win32_binary(major, minor, micro)
114
+ if ENV["RROONGA_USE_GROONGA_X64"]
115
+ architecture = "x64"
116
+ else
117
+ architecture = "x86"
118
+ end
119
+ zip = "groonga-#{major}.#{minor}.#{micro}-#{architecture}.zip"
120
+ url = "http://packages.groonga.org/windows/groonga/#{zip}"
121
+ install_dir = local_groonga_install_dir
122
+
123
+ download(url)
124
+
125
+ message("extracting...")
126
+ extract_zip(zip, ".")
127
+ message(" done\n")
128
+
129
+ if File.exist?(install_dir)
130
+ message("remove old install... #{install_dir}")
131
+ FileUtils.rm_rf(install_dir)
132
+ message(" done\n")
133
+ end
134
+
135
+ message("install...")
136
+ FileUtils.mv(File.basename(zip, ".zip"), install_dir)
137
+ message(" done\n")
138
+ end
139
+
140
+ def configure_command_line(prefix)
141
+ command_line = ["./configure"]
142
+ debug_build_p = ENV["RROONGA_DEBUG_BUILD"] == "yes"
143
+ debug_flags = ["CFLAGS=-ggdb3 -O0", "CXXFLAGS=-ggdb3 -O0"]
144
+ command_line.concat(debug_flags) if debug_build_p
145
+ command_line << "--prefix=#{prefix}"
146
+ escaped_command_line = command_line.collect do |command|
147
+ Shellwords.escape(command)
148
+ end
149
+ escaped_command_line.join(" ")
150
+ end
151
+
152
+ def build_groonga(major, minor, micro)
153
+ tar_gz = "groonga-#{major}.#{minor}.#{micro}.tar.gz"
154
+ url = "http://packages.groonga.org/source/groonga/#{tar_gz}"
155
+ install_dir = local_groonga_install_dir
156
+
157
+ download(url)
158
+
159
+ message("extracting...")
160
+ if xsystem("tar xfz #{tar_gz}")
161
+ message(" done\n")
162
+ else
163
+ message(" failed\n")
164
+ exit(false)
165
+ end
83
166
 
84
- message("extracting...")
85
- if xsystem("tar xfz #{tar_gz}")
167
+ groonga_source_dir = "groonga-#{major}.#{minor}.#{micro}"
168
+ Dir.chdir(groonga_source_dir) do
169
+ message("configuring...")
170
+ if xsystem(configure_command_line(install_dir))
86
171
  message(" done\n")
87
172
  else
88
173
  message(" failed\n")
89
- exit 1
174
+ exit(false)
90
175
  end
91
176
 
92
- groonga_source_dir = "groonga-#{major}.#{minor}.#{micro}"
93
- Dir.chdir(groonga_source_dir) do
94
- message("configuring...")
95
- prefix = Shellwords.escape(install_dir)
96
- if xsystem("./configure CFLAGS='-g -O0' --prefix=#{prefix}")
97
- message(" done\n")
98
- else
99
- message(" failed\n")
100
- exit 1
101
- end
102
-
103
- message("building (maybe long time)...")
104
- if xsystem("make")
105
- message(" done\n")
106
- else
107
- message(" failed\n")
108
- exit 1
109
- end
177
+ message("building (maybe long time)...")
178
+ if xsystem("make")
179
+ message(" done\n")
180
+ else
181
+ message(" failed\n")
182
+ exit(false)
183
+ end
110
184
 
111
- message("installing...")
112
- if [major, minor, micro] == [0, 1, 6]
113
- make_install_args = " MKDIR_P='mkdir -p --'"
114
- else
115
- make_install_args = ""
116
- end
117
- if xsystem("make install#{make_install_args}")
118
- message(" done\n")
119
- else
120
- message(" failed\n")
121
- exit 1
122
- end
185
+ message("installing...")
186
+ if [major, minor, micro] == [0, 1, 6]
187
+ make_install_args = " MKDIR_P='mkdir -p --'"
188
+ else
189
+ make_install_args = ""
190
+ end
191
+ if xsystem("make install#{make_install_args}")
192
+ message(" done\n")
193
+ else
194
+ message(" failed\n")
195
+ exit(false)
123
196
  end
124
197
  end
125
-
126
- prepend_pkg_config_path_for_local_groonga
127
198
  end
128
199
 
129
200
  unless PKGConfig.have_package(package_name, major, minor, micro)
@@ -66,9 +66,13 @@ rb_grn_context_register_floating_object (RbGrnObject *rb_grn_object)
66
66
  grn_ctx *context;
67
67
  grn_hash *floating_objects;
68
68
 
69
- Data_Get_Struct(rb_grn_object->rb_context, RbGrnContext, rb_grn_context);
69
+ rb_grn_context = rb_grn_object->rb_grn_context;
70
70
  context = rb_grn_context->context;
71
71
  floating_objects = rb_grn_context->floating_objects;
72
+ if (!floating_objects) {
73
+ rb_grn_context_reset_floating_objects(rb_grn_context);
74
+ floating_objects = rb_grn_context->floating_objects;
75
+ }
72
76
  grn_hash_add(context, floating_objects,
73
77
  (const void *)(&rb_grn_object), sizeof(RbGrnObject *),
74
78
  NULL, NULL);
@@ -85,7 +89,10 @@ rb_grn_context_unregister_floating_object (RbGrnObject *rb_grn_object)
85
89
  if (!rb_grn_object->floating)
86
90
  return;
87
91
 
88
- Data_Get_Struct(rb_grn_object->rb_context, RbGrnContext, rb_grn_context);
92
+ rb_grn_context = rb_grn_object->rb_grn_context;
93
+ if (!rb_grn_context)
94
+ return;
95
+
89
96
  context = rb_grn_context->context;
90
97
  floating_objects = rb_grn_context->floating_objects;
91
98
  grn_hash_delete(context, floating_objects,
@@ -94,7 +101,7 @@ rb_grn_context_unregister_floating_object (RbGrnObject *rb_grn_object)
94
101
  rb_grn_object->floating = GRN_FALSE;
95
102
  }
96
103
 
97
- static void
104
+ void
98
105
  rb_grn_context_close_floating_objects (RbGrnContext *rb_grn_context)
99
106
  {
100
107
  grn_ctx *context;
@@ -114,6 +121,19 @@ rb_grn_context_close_floating_objects (RbGrnContext *rb_grn_context)
114
121
  grn_hash_close(context, floating_objects);
115
122
  }
116
123
 
124
+ void
125
+ rb_grn_context_reset_floating_objects (RbGrnContext *rb_grn_context)
126
+ {
127
+ grn_ctx *context;
128
+
129
+ rb_grn_context_close_floating_objects(rb_grn_context);
130
+ context = rb_grn_context->context;
131
+ rb_grn_context->floating_objects = grn_hash_create(context, NULL,
132
+ sizeof(RbGrnObject *),
133
+ 0,
134
+ GRN_OBJ_TABLE_HASH_KEY);
135
+ }
136
+
117
137
  static void
118
138
  rb_grn_context_unlink_database (grn_ctx *context)
119
139
  {
@@ -421,10 +441,8 @@ rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
421
441
  rb_grn_context_check(context, self);
422
442
 
423
443
  GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
424
- rb_grn_context->floating_objects = grn_hash_create(context, NULL,
425
- sizeof(RbGrnObject *),
426
- 0,
427
- GRN_OBJ_TABLE_HASH_KEY);
444
+ rb_grn_context->floating_objects = NULL;
445
+ rb_grn_context_reset_floating_objects(rb_grn_context);
428
446
  grn_ctx_set_finalizer(context, rb_grn_context_finalizer);
429
447
 
430
448
  if (!NIL_P(rb_encoding)) {
@@ -119,6 +119,21 @@ rb_grn_database_deconstruct (RbGrnObject *rb_grn_database,
119
119
  range_id, range);
120
120
  }
121
121
 
122
+ void
123
+ rb_grn_database_finalizer (grn_ctx *context,
124
+ RbGrnContext *rb_grn_context,
125
+ grn_obj *column,
126
+ RbGrnObject *rb_grn_database)
127
+ {
128
+ if (rb_grn_context) {
129
+ rb_grn_context_close_floating_objects(rb_grn_context);
130
+ }
131
+
132
+ if (!(context->flags & GRN_CTX_PER_DB)) {
133
+ grn_ctx_use(context, NULL);
134
+ }
135
+ }
136
+
122
137
  /*
123
138
  * Document-method: close
124
139
  *
@@ -140,6 +155,14 @@ rb_grn_database_close (VALUE self)
140
155
  return rb_grn_object_close(self);
141
156
  }
142
157
 
158
+ static void
159
+ reset_floating_objects (VALUE rb_context)
160
+ {
161
+ RbGrnContext *rb_grn_context;
162
+ Data_Get_Struct(rb_context, RbGrnContext, rb_grn_context);
163
+ rb_grn_context_reset_floating_objects(rb_grn_context);
164
+ }
165
+
143
166
  /*
144
167
  * call-seq:
145
168
  * Groonga::Database.create(options=nil) -> Groonga::Database
@@ -195,6 +218,7 @@ rb_grn_database_s_create (int argc, VALUE *argv, VALUE klass)
195
218
  old_database = grn_ctx_db(context);
196
219
  if (old_database)
197
220
  grn_obj_unlink(context, old_database);
221
+ reset_floating_objects(rb_context);
198
222
  database = grn_db_create(context, path, &create_args);
199
223
  rb_grn_context_check(context, rb_ary_new4(argc, argv));
200
224
  owner = (context->flags & GRN_CTX_PER_DB) ? GRN_FALSE : GRN_TRUE;
@@ -249,6 +273,7 @@ rb_grn_database_initialize (int argc, VALUE *argv, VALUE self)
249
273
  old_database = grn_ctx_db(context);
250
274
  if (old_database)
251
275
  grn_obj_unlink(context, old_database);
276
+ reset_floating_objects(rb_context);
252
277
  database = grn_db_open(context, path);
253
278
  rb_grn_object_assign(Qnil, self, rb_context, context, database);
254
279
  rb_grn_context_check(context, self);