rroonga 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -302,14 +302,12 @@ module Groonga
302
302
  def column_method(column)
303
303
  range = column.range
304
304
  case range.name
305
- when "Int32"
306
- "integer32"
307
- when "Int64"
308
- "integer64"
309
- when "UInt32"
310
- "unsigned_integer32"
311
- when "UInt64"
312
- "unsigned_integer64"
305
+ when "Bool"
306
+ "boolean"
307
+ when /\AInt(8|16|32|64)\z/
308
+ "integer#{$1}"
309
+ when /\AUInt(8|16|32|64)\z/
310
+ "unsigned_integer#{$1}"
313
311
  when "Float"
314
312
  "float"
315
313
  when "Time"
@@ -320,6 +318,10 @@ module Groonga
320
318
  "text"
321
319
  when "LongText"
322
320
  "long_text"
321
+ when "TokyoGeoPoint"
322
+ "tokyo_geo_point"
323
+ when "WGS84GeoPoint"
324
+ "wgs84_geo_point"
323
325
  else
324
326
  raise ArgumentError, "unsupported column: #{column.inspect}"
325
327
  end
@@ -161,6 +161,13 @@ module Groonga
161
161
  self["_score"]
162
162
  end
163
163
 
164
+ # Sets score. Score column exists only search result table.
165
+ #
166
+ # @param [Integer] new_score The new score.
167
+ def score=(new_score)
168
+ self["_score"] = new_score
169
+ end
170
+
164
171
  # Groonga::Record#scoreが利用できる場合は +true+ を
165
172
  # 返す。
166
173
  def support_score?
@@ -516,6 +516,10 @@ module Groonga
516
516
  "text" => "Text",
517
517
  "binary" => "LongText",
518
518
  "long_text" => "LongText",
519
+ "int8" => "Int8",
520
+ "integer8" => "Int8",
521
+ "int16" => "Int16",
522
+ "integer16" => "Int16",
519
523
  "int" => "Int32",
520
524
  "integer" => "Int32",
521
525
  "int32" => "Int32",
@@ -523,6 +527,10 @@ module Groonga
523
527
  "decimal" => "Int64",
524
528
  "int64" => "Int64",
525
529
  "integer64" => "Int64",
530
+ "uint8" => "UInt8",
531
+ "unsigned_integer8" => "UInt8",
532
+ "uint16" => "UInt16",
533
+ "unsigned_integer16" => "UInt16",
526
534
  "uint" => "UInt32",
527
535
  "unsigned_integer" => "UInt32",
528
536
  "uint32" => "UInt32",
@@ -535,6 +543,9 @@ module Groonga
535
543
  "time" => "Time",
536
544
  "date" => "Time",
537
545
  "boolean" => "Bool",
546
+ "tokyo_geo_point" => "TokyoGeoPoint",
547
+ "geo_point" => "WGS84GeoPoint",
548
+ "wgs84_geo_point" => "WGS84GeoPoint",
538
549
  "delimit" => "TokenDelimit",
539
550
  "token_delimit" => "TokenDelimit",
540
551
  "unigram" => "TokenUnigram",
@@ -1158,6 +1169,28 @@ module Groonga
1158
1169
  self
1159
1170
  end
1160
1171
 
1172
+ # Defines a 8 bit signed integer column named @name@.
1173
+ #
1174
+ # @param [String or Symbol] name the column name
1175
+ # @param [Hash] options ({}) the options
1176
+ # @see Groonga::Schema::TableDefinition#column for
1177
+ # available @options@.
1178
+ def integer8(name, options={})
1179
+ column(name, "Int8", options)
1180
+ end
1181
+ alias_method :int8, :integer8
1182
+
1183
+ # Defines a 16 bit signed integer column named @name@.
1184
+ #
1185
+ # @param [String or Symbol] name the column name
1186
+ # @param [Hash] options ({}) the options
1187
+ # @see Groonga::Schema::TableDefinition#column for
1188
+ # available @options@.
1189
+ def integer16(name, options={})
1190
+ column(name, "Int16", options)
1191
+ end
1192
+ alias_method :int16, :integer16
1193
+
1161
1194
  # 名前が _name_ の32bit符号付き整数のカラムを作成する。
1162
1195
  #
1163
1196
  # _options_ に指定可能な値は
@@ -1177,6 +1210,28 @@ module Groonga
1177
1210
  end
1178
1211
  alias_method :int64, :integer64
1179
1212
 
1213
+ # Defines a 8 bit unsigned integer column named @name@.
1214
+ #
1215
+ # @param [String or Symbol] name the column name
1216
+ # @param [Hash] options ({}) the options
1217
+ # @see Groonga::Schema::TableDefinition#column for
1218
+ # available @options@.
1219
+ def unsigned_integer8(name, options={})
1220
+ column(name, "UInt8", options)
1221
+ end
1222
+ alias_method :uint8, :unsigned_integer8
1223
+
1224
+ # Defines a 16 bit unsigned integer column named @name@.
1225
+ #
1226
+ # @param [String or Symbol] name the column name
1227
+ # @param [Hash] options ({}) the options
1228
+ # @see Groonga::Schema::TableDefinition#column for
1229
+ # available @options@.
1230
+ def unsigned_integer16(name, options={})
1231
+ column(name, "UInt16", options)
1232
+ end
1233
+ alias_method :uint16, :unsigned_integer16
1234
+
1180
1235
  # 名前が _name_ の32bit符号なし整数のカラムを作成する。
1181
1236
  #
1182
1237
  # _options_ に指定可能な値は
@@ -1272,6 +1327,40 @@ module Groonga
1272
1327
  end
1273
1328
  alias_method :bool, :boolean
1274
1329
 
1330
+ # Defines a 8 bit signed integer column named @name@.
1331
+ #
1332
+ # @param [String or Symbol] name the column name
1333
+ # @param [Hash] options ({}) the options
1334
+ # @see Groonga::Schema::TableDefinition#column for
1335
+ # available @options@.
1336
+ def integer8(name, options={})
1337
+ column(name, "Int8", options)
1338
+ end
1339
+ alias_method :int8, :integer8
1340
+
1341
+ # Defines a geo point in Tokyo geodetic system column
1342
+ # named @name@.
1343
+ #
1344
+ # @param [String or Symbol] name the column name
1345
+ # @param [Hash] options ({}) the options
1346
+ # @see Groonga::Schema::TableDefinition#column for
1347
+ # available @options@.
1348
+ def tokyo_geo_point(name, options={})
1349
+ column(name, "TokyoGeoPoint", options)
1350
+ end
1351
+
1352
+ # Defines a geo point in WGS 84 (World Geodetic System) column
1353
+ # named @name@.
1354
+ #
1355
+ # @param [String or Symbol] name the column name
1356
+ # @param [Hash] options ({}) the options
1357
+ # @see Groonga::Schema::TableDefinition#column for
1358
+ # available @options@.
1359
+ def wgs84_geo_point(name, options={})
1360
+ column(name, "WGS84GeoPoint", options)
1361
+ end
1362
+ alias_method :geo_point, :wgs84_geo_point
1363
+
1275
1364
  # @private
1276
1365
  def [](name, definition_class=nil)
1277
1366
  @definitions.find do |definition|
@@ -1651,23 +1740,25 @@ module Groonga
1651
1740
  end
1652
1741
  end
1653
1742
  table.define_column(@name,
1654
- normalize_type(context),
1743
+ resolved_type(context),
1655
1744
  options)
1656
1745
  end
1657
1746
 
1658
1747
  private
1659
- def normalize_type(context)
1748
+ def resolved_type(context)
1749
+ return @type if @type.is_a?(Groonga::Object)
1660
1750
  if @type.respond_to?(:call)
1661
- resolved_type = @type.call(context)
1751
+ resolved_type_name = @type.call(context)
1662
1752
  else
1663
- resolved_type = @type
1753
+ resolved_type_name = @type
1664
1754
  end
1665
- Schema.normalize_type(resolved_type, :context => context)
1755
+ normalized_type_name = Schema.normalize_type(resolved_type_name,
1756
+ :context => context)
1757
+ context[normalized_type_name]
1666
1758
  end
1667
1759
 
1668
1760
  def same_column?(context, column)
1669
- # TODO: should check column type and other options.
1670
- column.range == context[normalize_type(context)]
1761
+ column.range == resolved_type(context)
1671
1762
  end
1672
1763
 
1673
1764
  def define_options(context, table)
data/rroonga-build.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009-2011 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
@@ -18,8 +18,8 @@
18
18
  module RroongaBuild
19
19
  module RequiredGroongaVersion
20
20
  MAJOR = 1
21
- MINOR = 2
22
- MICRO = 8
21
+ MINOR = 3
22
+ MICRO = 0
23
23
  VERSION = [MAJOR, MINOR, MICRO]
24
24
  end
25
25
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2010-2012 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -13,7 +13,7 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
- class ContextSelectTest < Test::Unit::TestCase
16
+ class CommandSelectTest < Test::Unit::TestCase
17
17
  include GroongaTestUtils
18
18
 
19
19
  setup :setup_database
@@ -100,7 +100,7 @@ class ContextSelectTest < Test::Unit::TestCase
100
100
 
101
101
  def test_drill_down_with_no_hit
102
102
  result = context.select(@users,
103
- :filter => "_key == \"no hit\"",
103
+ :filter => "_key == \"no\\ hit\"",
104
104
  :output_columns => ["_key"],
105
105
  :drill_down => ["_key", "book"],
106
106
  :drill_down_output_columns => "_key",
data/test/test-record.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -233,6 +233,23 @@ class RecordTest < Test::Unit::TestCase
233
233
  end)
234
234
  end
235
235
 
236
+ def test_score=
237
+ groonga = @bookmarks.add
238
+ groonga["content"] = "full text search search search engine."
239
+
240
+ google = @bookmarks.add
241
+ google["content"] = "Web search engine."
242
+
243
+ results = @bookmarks_content_index.search("search")
244
+ results.each do |record|
245
+ record.score *= 10
246
+ end
247
+ assert_equal([[groonga.id, 30], [google.id, 10]],
248
+ results.collect do |record|
249
+ [record.id, record.score]
250
+ end)
251
+ end
252
+
236
253
  def test_increment!
237
254
  groonga = @bookmarks.add
238
255
  assert_equal(0, groonga["rate"])
@@ -28,6 +28,29 @@ class SchemaDumperTest < Test::Unit::TestCase
28
28
  end
29
29
  end
30
30
 
31
+ def define_built_in_types_schema
32
+ Groonga::Schema.define do |schema|
33
+ schema.create_table("Posts") do |table|
34
+ table.boolean :public
35
+ table.int8 :int8
36
+ table.uint8 :uint8
37
+ table.int16 :int16
38
+ table.uint16 :uint16
39
+ table.int32 :int32
40
+ table.uint32 :uint32
41
+ table.int64 :int64
42
+ table.uint64 :uint64
43
+ table.float :vote_average
44
+ table.time :published_at
45
+ table.short_text :title
46
+ table.text :content
47
+ table.long_text :attachment
48
+ table.tokyo_geo_point :location_tokyo
49
+ table.wgs84_geo_point :location_wgs84
50
+ end
51
+ end
52
+ end
53
+
31
54
  def define_reference_schema
32
55
  Groonga::Schema.define do |schema|
33
56
  schema.create_table("Items") do |table|
@@ -79,6 +102,31 @@ end
79
102
  EOS
80
103
  end
81
104
 
105
+ def test_built_in_types
106
+ define_built_in_types_schema
107
+ assert_equal(<<-EOS, dump)
108
+ create_table("Posts",
109
+ :force => true) do |table|
110
+ table.long_text("attachment")
111
+ table.text("content")
112
+ table.integer16("int16")
113
+ table.integer32("int32")
114
+ table.integer64("int64")
115
+ table.integer8("int8")
116
+ table.tokyo_geo_point("location_tokyo")
117
+ table.wgs84_geo_point("location_wgs84")
118
+ table.boolean("public")
119
+ table.time("published_at")
120
+ table.short_text("title")
121
+ table.unsigned_integer16("uint16")
122
+ table.unsigned_integer32("uint32")
123
+ table.unsigned_integer64("uint64")
124
+ table.unsigned_integer8("uint8")
125
+ table.float("vote_average")
126
+ end
127
+ EOS
128
+ end
129
+
82
130
  def test_reference
83
131
  define_reference_schema
84
132
  assert_equal(<<-EOS, dump)
@@ -33,6 +33,18 @@ class SchemaTypeTest < Test::Unit::TestCase
33
33
  assert_normalize_type("LongText", "LongText")
34
34
  end
35
35
 
36
+ def test_normalize_integer8
37
+ assert_normalize_type("Int8", "int8")
38
+ assert_normalize_type("Int8", "integer8")
39
+ assert_normalize_type("Int8", "Int8")
40
+ end
41
+
42
+ def test_normalize_integer16
43
+ assert_normalize_type("Int16", "int16")
44
+ assert_normalize_type("Int16", "integer16")
45
+ assert_normalize_type("Int16", "Int16")
46
+ end
47
+
36
48
  def test_normalize_integer32
37
49
  assert_normalize_type("Int32", "int")
38
50
  assert_normalize_type("Int32", "integer")
@@ -47,6 +59,18 @@ class SchemaTypeTest < Test::Unit::TestCase
47
59
  assert_normalize_type("Int64", "Int64")
48
60
  end
49
61
 
62
+ def test_normalize_unsigned_integer8
63
+ assert_normalize_type("UInt8", "uint8")
64
+ assert_normalize_type("UInt8", "unsigned_integer8")
65
+ assert_normalize_type("UInt8", "UInt8")
66
+ end
67
+
68
+ def test_normalize_unsigned_integer16
69
+ assert_normalize_type("UInt16", "uint16")
70
+ assert_normalize_type("UInt16", "unsigned_integer16")
71
+ assert_normalize_type("UInt16", "UInt16")
72
+ end
73
+
50
74
  def test_normalize_unsigned_integer32
51
75
  assert_normalize_type("UInt32", "uint")
52
76
  assert_normalize_type("UInt32", "unsigned_integer")
@@ -79,6 +103,17 @@ class SchemaTypeTest < Test::Unit::TestCase
79
103
  assert_normalize_type("Bool", "Bool")
80
104
  end
81
105
 
106
+ def test_normalize_tokyo_geo_point
107
+ assert_normalize_type("TokyoGeoPoint", "tokyo_geo_point")
108
+ assert_normalize_type("TokyoGeoPoint", "TokyoGeoPoint")
109
+ end
110
+
111
+ def test_normalize_wgs84_geo_point
112
+ assert_normalize_type("WGS84GeoPoint", "geo_point")
113
+ assert_normalize_type("WGS84GeoPoint", "wgs84_geo_point")
114
+ assert_normalize_type("WGS84GeoPoint", "WGS84GeoPoint")
115
+ end
116
+
82
117
  def test_normalize_delimit
83
118
  assert_normalize_type("TokenDelimit", "delimit")
84
119
  assert_normalize_type("TokenDelimit", "token_delimit")
data/test/test-schema.rb CHANGED
@@ -343,6 +343,22 @@ class SchemaTest < Test::Unit::TestCase
343
343
  end
344
344
  end
345
345
 
346
+ def test_integer8_column
347
+ assert_nil(context["Posts.rate"])
348
+ Groonga::Schema.create_table("Posts") do |table|
349
+ table.integer8 :rate
350
+ end
351
+ assert_equal(context["Int8"], context["Posts.rate"].range)
352
+ end
353
+
354
+ def test_integer16_column
355
+ assert_nil(context["Posts.rate"])
356
+ Groonga::Schema.create_table("Posts") do |table|
357
+ table.integer16 :rate
358
+ end
359
+ assert_equal(context["Int16"], context["Posts.rate"].range)
360
+ end
361
+
346
362
  def test_integer32_column
347
363
  assert_nil(context["Posts.rate"])
348
364
  Groonga::Schema.create_table("Posts") do |table|
@@ -359,6 +375,22 @@ class SchemaTest < Test::Unit::TestCase
359
375
  assert_equal(context["Int64"], context["Posts.rate"].range)
360
376
  end
361
377
 
378
+ def test_unsigned_integer8_column
379
+ assert_nil(context["Posts.n_viewed"])
380
+ Groonga::Schema.create_table("Posts") do |table|
381
+ table.unsigned_integer8 :n_viewed
382
+ end
383
+ assert_equal(context["UInt8"], context["Posts.n_viewed"].range)
384
+ end
385
+
386
+ def test_unsigned_integer16_column
387
+ assert_nil(context["Posts.n_viewed"])
388
+ Groonga::Schema.create_table("Posts") do |table|
389
+ table.unsigned_integer16 :n_viewed
390
+ end
391
+ assert_equal(context["UInt16"], context["Posts.n_viewed"].range)
392
+ end
393
+
362
394
  def test_unsigned_integer32_column
363
395
  assert_nil(context["Posts.n_viewed"])
364
396
  Groonga::Schema.create_table("Posts") do |table|
@@ -433,6 +465,30 @@ class SchemaTest < Test::Unit::TestCase
433
465
  assert_equal(context["Bool"], context["Posts.public"].range)
434
466
  end
435
467
 
468
+ def test_tokyo_geo_point_column
469
+ assert_nil(context["Posts.location"])
470
+ Groonga::Schema.create_table("Posts") do |table|
471
+ table.tokyo_geo_point :location
472
+ end
473
+ assert_equal(context["TokyoGeoPoint"], context["Posts.location"].range)
474
+ end
475
+
476
+ def test_wgs84_geo_point_column
477
+ assert_nil(context["Posts.location"])
478
+ Groonga::Schema.create_table("Posts") do |table|
479
+ table.wgs84_geo_point :location
480
+ end
481
+ assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range)
482
+ end
483
+
484
+ def test_geo_point_column
485
+ assert_nil(context["Posts.location"])
486
+ Groonga::Schema.create_table("Posts") do |table|
487
+ table.geo_point :location
488
+ end
489
+ assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range)
490
+ end
491
+
436
492
  def test_remove_column
437
493
  Groonga::Schema.create_table("Posts") do |table|
438
494
  table.long_text :content
@@ -456,26 +512,40 @@ class SchemaTest < Test::Unit::TestCase
456
512
  assert_equal("Posts.body", content.name)
457
513
  end
458
514
 
459
- def test_column_again
460
- Groonga::Schema.create_table("Posts") do |table|
461
- table.text :content
515
+ class DefineColumnAgainTest < self
516
+ def test_same_option
517
+ Groonga::Schema.create_table("Posts") do |table|
518
+ table.text :content
519
+ end
520
+
521
+ assert_nothing_raised do
522
+ Groonga::Schema.create_table("Posts") do |table|
523
+ table.text :content
524
+ end
525
+ end
462
526
  end
463
527
 
464
- assert_nothing_raised do
528
+ def test_difference_type
465
529
  Groonga::Schema.create_table("Posts") do |table|
466
530
  table.text :content
467
531
  end
468
- end
469
- end
470
532
 
471
- def test_column_again_with_difference_type
472
- Groonga::Schema.create_table("Posts") do |table|
473
- table.text :content
533
+ assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
534
+ Groonga::Schema.create_table("Posts") do |table|
535
+ table.integer :content
536
+ end
537
+ end
474
538
  end
475
539
 
476
- assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
540
+ def test_same_option_by_groonga_object
477
541
  Groonga::Schema.create_table("Posts") do |table|
478
- table.integer :content
542
+ table.text :content
543
+ end
544
+
545
+ assert_nothing_raised do
546
+ Groonga::Schema.create_table("Posts") do |table|
547
+ table.column(:content, Groonga["Text"])
548
+ end
479
549
  end
480
550
  end
481
551
  end