rufus-tokyo 0.1.14 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +9 -0
- data/CREDITS.txt +10 -1
- data/README.rdoc +9 -11
- data/TODO.txt +17 -5
- data/lib/rufus/edo/cabcore.rb +29 -6
- data/lib/rufus/edo/ntyrant/abstract.rb +1 -1
- data/lib/rufus/edo/ntyrant/table.rb +14 -0
- data/lib/rufus/edo/tabcore.rb +45 -18
- data/lib/rufus/tokyo.rb +1 -1
- data/lib/rufus/tokyo/cabinet/abstract.rb +33 -32
- data/lib/rufus/tokyo/cabinet/lib.rb +12 -17
- data/lib/rufus/tokyo/cabinet/table.rb +53 -20
- data/lib/rufus/tokyo/dystopia.rb +10 -7
- data/lib/rufus/tokyo/dystopia/core.rb +198 -0
- data/lib/rufus/tokyo/dystopia/lib.rb +65 -3
- data/lib/rufus/tokyo/dystopia/words.rb +1 -1
- data/lib/rufus/tokyo/outlen.rb +46 -0
- data/lib/rufus/tokyo/query.rb +9 -1
- data/lib/rufus/tokyo/tyrant/abstract.rb +4 -26
- data/lib/rufus/tokyo/tyrant/ext.rb +52 -0
- data/lib/rufus/tokyo/tyrant/lib.rb +6 -6
- data/lib/rufus/tokyo/tyrant/table.rb +3 -1
- data/lib/rufus/tokyo/utils.rb +44 -0
- data/spec/spec.rb +3 -1
- metadata +6 -2
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
= rufus-tokyo CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-tokyo - 1.0.0 released 2009/07/23
|
6
|
+
|
7
|
+
- todo : merged in Jeremy Hinegardner's Dystopia work
|
8
|
+
- issue #13 : to_s for keys and values (thanks Elise and Ilya)
|
9
|
+
- todo : added full-text search ops :ftsphrase, :ftsex, :ftsor and :ftsand
|
10
|
+
- todo : added inverted index types, :token, :qgram, :opt
|
11
|
+
- todo : dropped 'backward compability' TC[/TT] 1.4.28+ ftw
|
12
|
+
|
13
|
+
|
5
14
|
== rufus-tokyo - 0.1.14 released 2009/06/30
|
6
15
|
|
7
16
|
- issue #2 : query#add with no_index=false by default
|
data/CREDITS.txt
CHANGED
@@ -6,17 +6,26 @@
|
|
6
6
|
|
7
7
|
John Mettraux http://jmettraux.wordpress.com
|
8
8
|
Zev Blut http://www.iknow.co.jp/users/zev
|
9
|
+
Jeremy Hinegardner http://www.copiousfreetime.org/
|
9
10
|
|
10
11
|
|
11
12
|
== contributors
|
12
13
|
|
14
|
+
Adam Keys http://github.com/therealadam
|
15
|
+
Marcos Piccinini http://github.com/nofxx
|
13
16
|
Matthew King http://github.com/automatthew
|
14
17
|
Kamal Fariz Mahyuddin http://github.com/kamal
|
15
18
|
Justin Reagor http://blog.kineticweb.com/
|
16
|
-
|
19
|
+
Benjamin Yu http://github.com/byu
|
17
20
|
Mark 'mebaran' http://github.com/mebaran
|
18
21
|
|
19
22
|
|
23
|
+
== feedback / support
|
24
|
+
|
25
|
+
Ilya Grigorik http://igvita.com
|
26
|
+
Elise Huard http://blog.elisehuard.be/
|
27
|
+
|
28
|
+
|
20
29
|
== finally
|
21
30
|
|
22
31
|
many thanks to the author of Tokyo Cabinet (Mikio Hirabayashi) and
|
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ the rdoc is at http://rufus.rubyforge.org/rufus-tokyo/
|
|
29
29
|
|
30
30
|
== version [mis]match
|
31
31
|
|
32
|
-
this version of rufus-tokyo works with
|
32
|
+
this 'master' branch/version of rufus-tokyo works with
|
33
33
|
|
34
34
|
ffi 0.3.1, 0.3.5
|
35
35
|
|
@@ -37,16 +37,8 @@ this version of rufus-tokyo works with
|
|
37
37
|
ruby 1.9.1p129
|
38
38
|
jruby 1.1.6, 1.2.0, 1.3.1
|
39
39
|
|
40
|
-
TC 1.4.
|
41
|
-
TC 1.4.10 and TT 1.1.17 (adds the offset arg to query.limit)
|
42
|
-
TC 1.4.11 and TT 1.1.18
|
43
|
-
TC 1.4.13 and TT 1.1.22 (added query.count)
|
44
|
-
TC 1.4.21 and TT 1.1.27
|
45
|
-
TC 1.4.27 and TT 1.1.29
|
40
|
+
TC 1.4.27 / 28 and TT 1.1.29
|
46
41
|
|
47
|
-
tc-ruby 1.20 and tt-ruby 1.3 (Rufus::Edo)
|
48
|
-
tc-ruby 1.21 and tt-ruby 1.5 (Rufus::Edo)
|
49
|
-
tc-ruby 1.21 and tt-ruby 1.7 (Rufus::Edo)
|
50
42
|
tc-ruby 1.26 and tt-ruby 1.10 (Rufus::Edo)
|
51
43
|
|
52
44
|
|
@@ -268,6 +260,10 @@ On the rufus-ruby list :
|
|
268
260
|
|
269
261
|
http://groups.google.com/group/rufus-ruby
|
270
262
|
|
263
|
+
Note : Flinn Muller started an english speaking mailing list for TC / TT / TD
|
264
|
+
|
265
|
+
http://groups.google.com/group/tokyocabinet-users
|
266
|
+
|
271
267
|
|
272
268
|
== issue tracker
|
273
269
|
|
@@ -293,12 +289,14 @@ many thanks to the author of Tokyo Cabinet, Mikio Hirabayashi, and to the author
|
|
293
289
|
* http://tokyocabinet.sourceforge.net
|
294
290
|
* http://kenai.com/projects/ruby-ffi
|
295
291
|
|
292
|
+
dystopia interface developed with and sponsored by Seven Scale <http://sevenscale.com/>,
|
293
|
+
creators of Open Syslog.
|
296
294
|
|
297
295
|
== authors
|
298
296
|
|
299
297
|
* John Mettraux, jmettraux@gmail.com, http://jmettraux.wordpress.com
|
300
298
|
* Zev Blut, http://www.iknow.co.jp/users/zev
|
301
|
-
|
299
|
+
* Jeremy Hinegardner http://github.com/copiousfreetime (Tokyo Dystopia)
|
302
300
|
|
303
301
|
== the rest of Rufus
|
304
302
|
|
data/TODO.txt
CHANGED
@@ -7,19 +7,31 @@
|
|
7
7
|
|
8
8
|
[o] rdoc unix socket for tyrant
|
9
9
|
[o] edo : tran
|
10
|
-
[
|
10
|
+
[x] bench ux socket
|
11
11
|
|
12
12
|
[o] TT (TC) call [lua] function
|
13
|
-
[
|
13
|
+
[o] queryout
|
14
14
|
|
15
15
|
[o] impl lget/lput/ldelete in Rufus::Edo::Cabinet
|
16
16
|
|
17
|
-
[
|
17
|
+
[x] maybe supported different libs for migrations...
|
18
|
+
no, tctools are here for that.
|
18
19
|
|
19
|
-
[ ] document ENV['TOKYO_TYRANT_LIB'] & _CABINET_
|
20
|
+
[ ] document ENV['TOKYO_TYRANT_LIB'] & _CABINET_ / LD_LIBRARY_PATH
|
20
21
|
|
21
22
|
[o] unify m/l raise trick for util map/list
|
22
23
|
|
23
|
-
[
|
24
|
+
[o] misc calls (defrag) for Edo
|
24
25
|
[ ] TT set master & co
|
25
26
|
|
27
|
+
[o] drop 'backward compatibility' (post 0.1.14)
|
28
|
+
[o] qgram, token, opt inverted index types
|
29
|
+
[o] new query FTS conds
|
30
|
+
|
31
|
+
[ ] table/delete_keys_with_prefix, use searchout
|
32
|
+
|
33
|
+
[ ] first integration of Jeremy's work on Dystopia
|
34
|
+
|
35
|
+
[ ] implement q.metasearch(q, u)
|
36
|
+
[ ] kwic ?
|
37
|
+
|
data/lib/rufus/edo/cabcore.rb
CHANGED
@@ -73,19 +73,26 @@ module Rufus::Edo
|
|
73
73
|
# No comment
|
74
74
|
#
|
75
75
|
def []= (k, v)
|
76
|
+
|
77
|
+
k = k.to_s; v = v.to_s
|
78
|
+
|
76
79
|
@db.put(k, v) || raise_error
|
77
80
|
end
|
78
81
|
|
79
82
|
# No comment
|
80
83
|
#
|
81
84
|
def putkeep (k, v)
|
85
|
+
|
86
|
+
k = k.to_s; v = v.to_s
|
87
|
+
|
82
88
|
@db.putkeep(k, v)
|
83
89
|
end
|
84
90
|
|
85
91
|
# (The actual #[] method is provided by HashMethods)
|
86
92
|
#
|
87
93
|
def get (k)
|
88
|
-
|
94
|
+
|
95
|
+
@db.get(k.to_s)
|
89
96
|
end
|
90
97
|
protected :get
|
91
98
|
|
@@ -93,13 +100,17 @@ module Rufus::Edo
|
|
93
100
|
# else nil.
|
94
101
|
#
|
95
102
|
def delete (k)
|
103
|
+
|
104
|
+
k = k.to_s
|
96
105
|
v = self[k]
|
106
|
+
|
97
107
|
@db.out(k) ? v : nil
|
98
108
|
end
|
99
109
|
|
100
110
|
# Returns the number of records in the 'cabinet'
|
101
111
|
#
|
102
112
|
def size
|
113
|
+
|
103
114
|
@db.rnum
|
104
115
|
end
|
105
116
|
|
@@ -108,13 +119,16 @@ module Rufus::Edo
|
|
108
119
|
# Returns self (like Ruby's Hash does).
|
109
120
|
#
|
110
121
|
def clear
|
122
|
+
|
111
123
|
@db.vanish || raise_error
|
124
|
+
|
112
125
|
self
|
113
126
|
end
|
114
127
|
|
115
128
|
# Returns the 'weight' of the db (in bytes)
|
116
129
|
#
|
117
130
|
def weight
|
131
|
+
|
118
132
|
@db.fsiz
|
119
133
|
end
|
120
134
|
|
@@ -122,6 +136,7 @@ module Rufus::Edo
|
|
122
136
|
# returns true in case of success.
|
123
137
|
#
|
124
138
|
def close
|
139
|
+
|
125
140
|
@db.close || raise_error
|
126
141
|
end
|
127
142
|
|
@@ -130,6 +145,7 @@ module Rufus::Edo
|
|
130
145
|
# Returns true if it was successful.
|
131
146
|
#
|
132
147
|
def copy (target_path)
|
148
|
+
|
133
149
|
@db.copy(target_path)
|
134
150
|
end
|
135
151
|
|
@@ -139,6 +155,7 @@ module Rufus::Edo
|
|
139
155
|
# space, hence the 'compact' label...
|
140
156
|
#
|
141
157
|
def compact_copy (target_path)
|
158
|
+
|
142
159
|
@other_db = self.class.new(target_path)
|
143
160
|
self.each { |k, v| @other_db[k] = v }
|
144
161
|
@other_db.close
|
@@ -148,6 +165,7 @@ module Rufus::Edo
|
|
148
165
|
# the file and the device"
|
149
166
|
#
|
150
167
|
def sync
|
168
|
+
|
151
169
|
@db.sync || raise_error
|
152
170
|
end
|
153
171
|
|
@@ -206,6 +224,8 @@ module Rufus::Edo
|
|
206
224
|
#
|
207
225
|
def lget (keys)
|
208
226
|
|
227
|
+
keys = keys.collect { |k| k.to_s }
|
228
|
+
|
209
229
|
# only ADB has the #misc method...
|
210
230
|
|
211
231
|
if @db.respond_to?(:misc)
|
@@ -215,8 +235,7 @@ module Rufus::Edo
|
|
215
235
|
end
|
216
236
|
end
|
217
237
|
|
218
|
-
#
|
219
|
-
# default impl provided by HashMethods
|
238
|
+
# Default impl provided by HashMethods
|
220
239
|
#
|
221
240
|
def merge! (hash)
|
222
241
|
|
@@ -237,6 +256,8 @@ module Rufus::Edo
|
|
237
256
|
#
|
238
257
|
def ldelete (keys)
|
239
258
|
|
259
|
+
keys = keys.collect { |k| k.to_s }
|
260
|
+
|
240
261
|
# only ADB has the #misc method...
|
241
262
|
|
242
263
|
if @db.respond_to?(:misc)
|
@@ -253,6 +274,8 @@ module Rufus::Edo
|
|
253
274
|
#
|
254
275
|
def incr (key, val=1)
|
255
276
|
|
277
|
+
key = key.to_s
|
278
|
+
|
256
279
|
v = val.is_a?(Fixnum) ? @db.addint(key, val) : @db.adddouble(key, val)
|
257
280
|
|
258
281
|
raise(EdoError.new(
|
@@ -271,9 +294,9 @@ module Rufus::Edo
|
|
271
294
|
#
|
272
295
|
def defrag
|
273
296
|
|
274
|
-
raise(NotImplementedError.new(
|
275
|
-
|
276
|
-
)) unless @db.respond_to?(:misc)
|
297
|
+
#raise(NotImplementedError.new(
|
298
|
+
# "defrag (misc) only available when opening db with :type => :abstract"
|
299
|
+
#)) unless @db.respond_to?(:misc)
|
277
300
|
|
278
301
|
@db.misc('defrag', [])
|
279
302
|
end
|
@@ -122,7 +122,7 @@ module Rufus::Edo
|
|
122
122
|
#
|
123
123
|
# Nil is returned in case of failure.
|
124
124
|
#
|
125
|
-
def ext (func_name, key, value, opts={})
|
125
|
+
def ext (func_name, key='', value='', opts={})
|
126
126
|
|
127
127
|
@db.ext(func_name.to_s, key.to_s, value.to_s, compute_ext_opts(opts))
|
128
128
|
end
|
@@ -125,6 +125,20 @@ module Rufus::Edo
|
|
125
125
|
raise NoMethodError.new("NetTyrant : transactions not supported")
|
126
126
|
end
|
127
127
|
|
128
|
+
# Calls a lua embedded function
|
129
|
+
# (http://tokyocabinet.sourceforge.net/tyrantdoc/#luaext)
|
130
|
+
#
|
131
|
+
# Options are :global_locking and :record_locking
|
132
|
+
#
|
133
|
+
# Returns the return value of the called function.
|
134
|
+
#
|
135
|
+
# Nil is returned in case of failure.
|
136
|
+
#
|
137
|
+
def ext (func_name, key='', value='', opts={})
|
138
|
+
|
139
|
+
@db.ext(func_name.to_s, key.to_s, value.to_s, compute_ext_opts(opts))
|
140
|
+
end
|
141
|
+
|
128
142
|
protected
|
129
143
|
|
130
144
|
def table_query_class #:nodoc#
|
data/lib/rufus/edo/tabcore.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
#++
|
24
24
|
|
25
25
|
|
26
|
+
require 'rufus/tokyo/utils'
|
26
27
|
require 'rufus/tokyo/query'
|
27
28
|
require 'rufus/tokyo/transactions'
|
28
29
|
|
@@ -55,6 +56,10 @@ module Rufus::Edo
|
|
55
56
|
INDEX_TYPES = {
|
56
57
|
:lexical => 0,
|
57
58
|
:decimal => 1,
|
59
|
+
:token => 2,
|
60
|
+
:qgram => 3,
|
61
|
+
:opt => 9998,
|
62
|
+
:optimized => 9998,
|
58
63
|
:void => 9999,
|
59
64
|
:remove => 9999,
|
60
65
|
:keep => 1 << 24
|
@@ -62,16 +67,26 @@ module Rufus::Edo
|
|
62
67
|
|
63
68
|
# Sets an index on a column of the table.
|
64
69
|
#
|
65
|
-
# Types maybe be :lexical or :decimal
|
70
|
+
# Types maybe be :lexical or :decimal.
|
71
|
+
#
|
72
|
+
# Recently (TC 1.4.26 and 1.4.27) inverted indexes have been added,
|
73
|
+
# they are :token and :qgram. There is an :opt index as well.
|
74
|
+
#
|
75
|
+
# Sorry couldn't find any good doc about those inverted indexes apart from :
|
76
|
+
#
|
77
|
+
# http://alpha.mixi.co.jp/blog/?p=1147
|
78
|
+
# http://www.excite-webtl.jp/world/english/web/?wb_url=http%3A%2F%2Falpha.mixi.co.jp%2Fblog%2F%3Fp%3D1147&wb_lp=JAEN&wb_dis=2&wb_submit=+%96%7C+%96%F3+
|
79
|
+
#
|
80
|
+
# Use :keep to "add" and
|
66
81
|
# :remove (or :void) to "remove" an index.
|
67
82
|
#
|
68
83
|
# If column_name is :pk or "", the index will be set on the primary key.
|
69
84
|
#
|
70
|
-
#
|
85
|
+
# Returns true in case of success.
|
71
86
|
#
|
72
87
|
def set_index (column_name, *types)
|
73
88
|
|
74
|
-
column_name =
|
89
|
+
column_name = column_name == :pk ? '' : column_name.to_s
|
75
90
|
|
76
91
|
i = types.inject(0) { |i, t| i = i | INDEX_TYPES[t]; i }
|
77
92
|
|
@@ -91,9 +106,12 @@ module Rufus::Edo
|
|
91
106
|
#
|
92
107
|
def []= (pk, h_or_a)
|
93
108
|
|
109
|
+
pk = pk.to_s
|
110
|
+
|
94
111
|
m = h_or_a.is_a?(Hash) ? h_or_a : Hash[*h_or_a]
|
112
|
+
m = Rufus::Tokyo.h_or_a_to_s(m)
|
95
113
|
|
96
|
-
verify_value(m)
|
114
|
+
#verify_value(m)
|
97
115
|
|
98
116
|
@db.put(pk, m) || raise_error
|
99
117
|
end
|
@@ -107,7 +125,7 @@ module Rufus::Edo
|
|
107
125
|
#
|
108
126
|
def delete (k)
|
109
127
|
|
110
|
-
|
128
|
+
k = k.to_s
|
111
129
|
|
112
130
|
val = @db[k]
|
113
131
|
return nil unless val
|
@@ -175,6 +193,8 @@ module Rufus::Edo
|
|
175
193
|
#
|
176
194
|
def lget (keys)
|
177
195
|
|
196
|
+
keys = Rufus::Tokyo::h_or_a_to_s(keys)
|
197
|
+
|
178
198
|
if @db.respond_to?(:mget)
|
179
199
|
@db.mget(keys)
|
180
200
|
else
|
@@ -260,7 +280,7 @@ module Rufus::Edo
|
|
260
280
|
#
|
261
281
|
def get (k)
|
262
282
|
|
263
|
-
@db.get(k)
|
283
|
+
@db.get(k.to_s)
|
264
284
|
end
|
265
285
|
|
266
286
|
# Obviously something went wrong, let's ask the db about it and raise
|
@@ -274,17 +294,14 @@ module Rufus::Edo
|
|
274
294
|
raise EdoError.new("(err #{err_code}) #{err_msg}")
|
275
295
|
end
|
276
296
|
|
277
|
-
def verify_value (h)
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
"( #{k.inspect} => #{v.inspect} )")
|
286
|
-
}
|
287
|
-
end
|
297
|
+
#def verify_value (h)
|
298
|
+
# h.each { |k, v|
|
299
|
+
# next if k.is_a?(String) and v.is_a?(String)
|
300
|
+
# raise ArgumentError.new(
|
301
|
+
# "only String keys and values are accepted " +
|
302
|
+
# "( #{k.inspect} => #{v.inspect} )")
|
303
|
+
# }
|
304
|
+
#end
|
288
305
|
end
|
289
306
|
|
290
307
|
#
|
@@ -375,8 +392,18 @@ module Rufus::Edo
|
|
375
392
|
#
|
376
393
|
# :numoreq # number which is equal to at least one token
|
377
394
|
#
|
395
|
+
# :ftsph # full-text phrase search
|
396
|
+
# :ftsphrase
|
397
|
+
# :phrase
|
398
|
+
# :ftsand # full-text AND
|
399
|
+
# :ftsor # full-text OR
|
400
|
+
# :ftsex # full-text with 'compound' expression
|
401
|
+
#
|
378
402
|
def add (colname, operator, val, affirmative=true, no_index=false)
|
379
403
|
|
404
|
+
colname = colname.to_s
|
405
|
+
val = val.to_s
|
406
|
+
|
380
407
|
op = operator.is_a?(Fixnum) ? operator : OPERATORS[operator]
|
381
408
|
op = op | TDBQCNEGATE unless affirmative
|
382
409
|
op = op | TDBQCNOIDX if no_index
|
@@ -410,7 +437,7 @@ module Rufus::Edo
|
|
410
437
|
#
|
411
438
|
def order_by (colname, direction=:strasc)
|
412
439
|
|
413
|
-
@query.setorder(colname, DIRECTIONS[direction])
|
440
|
+
@query.setorder(colname.to_s, DIRECTIONS[direction])
|
414
441
|
end
|
415
442
|
|
416
443
|
# When set to true, only the primary keys of the matching records will
|