java_bin 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -23,3 +23,4 @@ Makefile
23
23
  *.o
24
24
  *.so
25
25
  *.log
26
+ *.orig
data/README.rdoc CHANGED
@@ -1,6 +1,80 @@
1
1
  = java_bin
2
2
 
3
- This is a Solr JavaBin format implementation for Ruby.
3
+ This is a Apache Solr JavaBin format (binary format) implementation for Ruby.
4
+
5
+ == Features
6
+
7
+ * fast parse, and less network traffic.
8
+ MRI 1.8.7
9
+ [data1]
10
+ ruby eval parse. 5000 times. elapsed time 1.31124
11
+ javabin parse. 5000 times. elapsed time 0.514837
12
+ 2.54690319460334 times
13
+
14
+ [data2]
15
+ ruby2 eval parse. 5000 times. elapsed time 6.604737
16
+ javabin2 parse. 5000 times. elapsed time 2.411031
17
+ 2.73938286152273 times
18
+
19
+ YARV 1.9.2
20
+ [data1]
21
+ ruby eval parse. 5000 times. elapsed time 1.35476947
22
+ javabin parse. 5000 times. elapsed time 0.370740373
23
+ 3.654226970311647 times
24
+
25
+ [data2]
26
+ ruby2 eval parse. 5000 times. elapsed time 6.555066861
27
+ javabin2 parse. 5000 times. elapsed time 1.752366331
28
+ 3.7406943656919647 times
29
+
30
+ * rsolr/solr-ruby support.
31
+ * pure and c extension code.
32
+ * ruby 1.8/1.9 support.
33
+
34
+ == Requirements
35
+
36
+ * Ruby1.8.7 or later (include 1.9.x)
37
+ * (recommended) C compiler: you can alos use java_bin without c extension, but 'pure' is 30 times slower than 'ext'.
38
+ * JavaBin has been tested with MRI 1.8.7, REE 1.8.7, YARV 1.9.2 pre1 on Ubuntu Linux 9.10 (32bit), and Apache Solr 1.4
39
+
40
+ == Install
41
+
42
+ gem sources -a http://gemcutter.org
43
+ gem install java_bin
44
+
45
+ == Simple Usage
46
+
47
+ require 'rubygems'
48
+ require 'java_bin'
49
+
50
+ @parser = JavaBin.parser.new
51
+ result = @parser.parse( java bin format string )
52
+
53
+ === With RSolr/Solr-Ruby
54
+
55
+ * By RSolr/Solr-Ruby support, a parser automatically uses javabin format instead of ruby format.
56
+
57
+ require 'rubygems'
58
+ require 'rsolr'
59
+ require 'java_bin'
60
+
61
+ solr = RSolr.connect
62
+ solr.select :q => '*:*'
63
+
64
+ == TODO
65
+
66
+ * more parse speed
67
+ * license
68
+ * windows build
69
+ * builder(writer)作成
70
+ * JRuby support
71
+
72
+ == References
73
+
74
+ * javabin http://wiki.apache.org/solr/javabin
75
+ * javabin codec (for java) http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/JavaBinCodec.java?view=markup
76
+ * rsolr http://github.com/mwmitchell/rsolr/
77
+ * solr-ruby http://wiki.apache.org/solr/solr-ruby
4
78
 
5
79
  == Note on Patches/Pull Requests
6
80
 
@@ -12,15 +86,6 @@ This is a Solr JavaBin format implementation for Ruby.
12
86
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
87
  * Send me a pull request. Bonus points for topic branches.
14
88
 
15
- == Install
16
-
17
- gem install java_bin
18
-
19
- == References
20
-
21
- * http://wiki.apache.org/solr/javabin
22
- * http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/JavaBinCodec.java?view=markup
23
-
24
89
  == Author
25
90
 
26
91
  Toshinori Kajihara <mailto:kennyj@gmail.com>
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "java_bin"
8
- gem.summary = %Q{Solr JavaBin format implementation for Ruby.}
9
- gem.description = %Q{Solr JavaBin format implementation for Ruby.}
8
+ gem.summary = %Q{Apache Solr JavaBin format implementation for Ruby.}
9
+ gem.description = %Q{Apache Solr JavaBin format (binary format) implementation for Ruby.}
10
10
  gem.email = "kennyj@gmail.com"
11
11
  gem.homepage = "http://github.com/kennyj/java_bin"
12
12
  gem.authors = ["kennyj"]
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  require 'rake/testtask'
22
22
  Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test' << 'ext'
23
+ test.libs << 'test' << 'ext'
24
24
  test.pattern = 'test/**/test_*.rb'
25
25
  test.verbose = true
26
26
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -304,6 +304,10 @@ static VALUE rb_cParser_parse(VALUE self, VALUE data) {
304
304
  Data_Get_Struct(self, JAVA_BIN_PARSER, ptr);
305
305
 
306
306
  /* 引数処理 */
307
+ if (TYPE(data) != T_STRING) {
308
+ rb_raise(rb_eRuntimeError, "rb_cParser_parse - data is not String.");
309
+ }
310
+
307
311
  SafeStringValue(data);
308
312
  ptrData = RSTRING_PTR(data);
309
313
  dataLen = RSTRING_LEN(data);
@@ -71,7 +71,7 @@ typedef struct _extern_string_info {
71
71
  /*
72
72
  * 読込処理データ保持構造体
73
73
  */
74
- typedef struct java_bin_reader {
74
+ typedef struct java_bin_parser {
75
75
  unsigned char* data;
76
76
  int data_len;
77
77
  int current;
@@ -83,7 +83,6 @@ typedef struct java_bin_reader {
83
83
  int cache_index;
84
84
  int last_string_offset;
85
85
  int last_string_len;
86
-
87
86
  } JAVA_BIN_PARSER;
88
87
 
89
88
  #ifdef HAVE_RUBY_ENCODING_H
Binary file
@@ -0,0 +1,300 @@
1
+ {
2
+ "responseHeader":{
3
+ "status":0,
4
+ "QTime":0,
5
+ "params":{
6
+ "indent":"on",
7
+ "start":"0",
8
+ "q":"*:*\r\n",
9
+ "wt":"json",
10
+ "version":"2.2",
11
+ "rows":"100"}},
12
+ "response":{"numFound":19,"start":0,"docs":[
13
+ {
14
+ "id":"SP2514N",
15
+ "name":"Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133",
16
+ "manu":"Samsung Electronics Co. Ltd.",
17
+ "price":92.0,
18
+ "popularity":6,
19
+ "inStock":true,
20
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
21
+ "cat":[
22
+ "electronics",
23
+ "hard drive"],
24
+ "features":[
25
+ "7200RPM, 8MB cache, IDE Ultra ATA-133",
26
+ "NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor"]},
27
+ {
28
+ "id":"6H500F0",
29
+ "name":"Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300",
30
+ "manu":"Maxtor Corp.",
31
+ "price":350.0,
32
+ "popularity":6,
33
+ "inStock":true,
34
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
35
+ "cat":[
36
+ "electronics",
37
+ "hard drive"],
38
+ "features":[
39
+ "SATA 3.0Gb/s, NCQ",
40
+ "8.5ms seek",
41
+ "16MB cache"]},
42
+ {
43
+ "id":"F8V7067-APL-KIT",
44
+ "name":"Belkin Mobile Power Cord for iPod w/ Dock",
45
+ "manu":"Belkin",
46
+ "weight":4.0,
47
+ "price":19.95,
48
+ "popularity":1,
49
+ "inStock":false,
50
+ "manufacturedate_dt":"2005-08-01T16:30:25Z",
51
+ "cat":[
52
+ "electronics",
53
+ "connector"],
54
+ "features":[
55
+ "car power adapter, white"]},
56
+ {
57
+ "id":"IW-02",
58
+ "name":"iPod & iPod Mini USB 2.0 Cable",
59
+ "manu":"Belkin",
60
+ "weight":2.0,
61
+ "price":11.5,
62
+ "popularity":1,
63
+ "inStock":false,
64
+ "manufacturedate_dt":"2006-02-14T23:55:59Z",
65
+ "cat":[
66
+ "electronics",
67
+ "connector"],
68
+ "features":[
69
+ "car power adapter for iPod, white"]},
70
+ {
71
+ "id":"MA147LL/A",
72
+ "name":"Apple 60 GB iPod with Video Playback Black",
73
+ "manu":"Apple Computer Inc.",
74
+ "includes":"earbud headphones, USB cable",
75
+ "weight":5.5,
76
+ "price":399.0,
77
+ "popularity":10,
78
+ "inStock":true,
79
+ "manufacturedate_dt":"2005-10-12T08:00:00Z",
80
+ "cat":[
81
+ "electronics",
82
+ "music"],
83
+ "features":[
84
+ "iTunes, Podcasts, Audiobooks",
85
+ "Stores up to 15,000 songs, 25,000 photos, or 150 hours of video",
86
+ "2.5-inch, 320x240 color TFT LCD display with LED backlight",
87
+ "Up to 20 hours of battery life",
88
+ "Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video",
89
+ "Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication"]},
90
+ {
91
+ "id":"TWINX2048-3200PRO",
92
+ "name":"CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail",
93
+ "manu":"Corsair Microsystems Inc.",
94
+ "price":185.0,
95
+ "popularity":5,
96
+ "inStock":true,
97
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
98
+ "cat":[
99
+ "electronics",
100
+ "memory"],
101
+ "features":[
102
+ "CAS latency 2,\t2-3-3-6 timing, 2.75v, unbuffered, heat-spreader"]},
103
+ {
104
+ "id":"VS1GB400C3",
105
+ "name":"CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail",
106
+ "manu":"Corsair Microsystems Inc.",
107
+ "price":74.99,
108
+ "popularity":7,
109
+ "inStock":true,
110
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
111
+ "cat":[
112
+ "electronics",
113
+ "memory"]},
114
+ {
115
+ "id":"VDBDB1A16",
116
+ "name":"A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM",
117
+ "manu":"A-DATA Technology Inc.",
118
+ "popularity":0,
119
+ "inStock":true,
120
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
121
+ "cat":[
122
+ "electronics",
123
+ "memory"],
124
+ "features":[
125
+ "CAS latency 3,\t 2.7v"]},
126
+ {
127
+ "id":"3007WFP",
128
+ "name":"Dell Widescreen UltraSharp 3007WFP",
129
+ "manu":"Dell, Inc.",
130
+ "includes":"USB cable",
131
+ "weight":401.6,
132
+ "price":2199.0,
133
+ "popularity":6,
134
+ "inStock":true,
135
+ "cat":[
136
+ "electronics",
137
+ "monitor"],
138
+ "features":[
139
+ "30\" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"]},
140
+ {
141
+ "id":"VA902B",
142
+ "name":"ViewSonic VA902B - flat panel display - TFT - 19\"",
143
+ "manu":"ViewSonic Corp.",
144
+ "weight":190.4,
145
+ "price":279.95,
146
+ "popularity":6,
147
+ "inStock":true,
148
+ "cat":[
149
+ "electronics",
150
+ "monitor"],
151
+ "features":[
152
+ "19\" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution"]},
153
+ {
154
+ "id":"0579B002",
155
+ "name":"Canon PIXMA MP500 All-In-One Photo Printer",
156
+ "manu":"Canon Inc.",
157
+ "weight":352.0,
158
+ "price":179.99,
159
+ "popularity":6,
160
+ "inStock":true,
161
+ "cat":[
162
+ "electronics",
163
+ "multifunction printer",
164
+ "printer",
165
+ "scanner",
166
+ "copier"],
167
+ "features":[
168
+ "Multifunction ink-jet color photo printer",
169
+ "Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi",
170
+ "2.5\" color LCD preview screen",
171
+ "Duplex Copying",
172
+ "Printing speed up to 29ppm black, 19ppm color",
173
+ "Hi-Speed USB",
174
+ "memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard"]},
175
+ {
176
+ "id":"TWINX2048-3200PRO-payload",
177
+ "name":"CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail",
178
+ "manu":"Corsair Microsystems Inc.",
179
+ "price":185.0,
180
+ "popularity":5,
181
+ "inStock":true,
182
+ "payloads":"electronics|6.0 memory|3.0",
183
+ "cat":[
184
+ "electronics",
185
+ "memory"],
186
+ "features":[
187
+ "CAS latency 2,\t2-3-3-6 timing, 2.75v, unbuffered, heat-spreader"]},
188
+ {
189
+ "id":"VS1GB400C3-payload",
190
+ "name":"CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail",
191
+ "manu":"Corsair Microsystems Inc.",
192
+ "price":74.99,
193
+ "popularity":7,
194
+ "inStock":true,
195
+ "payloads":"electronics|4.0 memory|2.0",
196
+ "cat":[
197
+ "electronics",
198
+ "memory"]},
199
+ {
200
+ "id":"VDBDB1A16-payload",
201
+ "name":"A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM",
202
+ "manu":"A-DATA Technology Inc.",
203
+ "popularity":5,
204
+ "inStock":true,
205
+ "payloads":"electronics|0.9 memory|0.1",
206
+ "cat":[
207
+ "electronics",
208
+ "memory"],
209
+ "features":[
210
+ "CAS latency 3,\t 2.7v"]},
211
+ {
212
+ "id":"9885A004",
213
+ "name":"Canon PowerShot SD500",
214
+ "manu":"Canon Inc.",
215
+ "includes":"32MB SD card, USB cable, AV cable, battery",
216
+ "weight":6.4,
217
+ "price":329.95,
218
+ "popularity":7,
219
+ "inStock":true,
220
+ "manufacturedate_dt":"2006-02-13T15:26:37Z",
221
+ "cat":[
222
+ "electronics",
223
+ "camera"],
224
+ "features":[
225
+ "3x zoop, 7.1 megapixel Digital ELPH",
226
+ "movie clips up to 640x480 @30 fps",
227
+ "2.0\" TFT LCD, 118,000 pixels",
228
+ "built in flash, red-eye reduction"]},
229
+ {
230
+ "id":"SOLR1000",
231
+ "name":"Solr, the Enterprise Search Server",
232
+ "manu":"Apache Software Foundation",
233
+ "price":0.0,
234
+ "popularity":10,
235
+ "inStock":true,
236
+ "incubationdate_dt":"2006-01-17T00:00:00Z",
237
+ "cat":[
238
+ "software",
239
+ "search"],
240
+ "features":[
241
+ "Advanced Full-Text Search Capabilities using Lucene",
242
+ "Optimized for High Volume Web Traffic",
243
+ "Standards Based Open Interfaces - XML and HTTP",
244
+ "Comprehensive HTML Administration Interfaces",
245
+ "Scalability - Efficient Replication to other Solr Search Servers",
246
+ "Flexible and Adaptable with XML configuration and Schema",
247
+ "Good unicode support: héllo (hello with an accent over the e)"]},
248
+ {
249
+ "id":"UTF8TEST",
250
+ "name":"Test with some UTF-8 encoded characters",
251
+ "manu":"Apache Software Foundation",
252
+ "price":0.0,
253
+ "inStock":true,
254
+ "cat":[
255
+ "software",
256
+ "search"],
257
+ "features":[
258
+ "No accents here",
259
+ "This is an e acute: é",
260
+ "eaiou with circumflexes: êâîôû",
261
+ "eaiou with umlauts: ëäïöü",
262
+ "tag with escaped chars: <nicetag/>",
263
+ "escaped ampersand: Bonnie & Clyde"]},
264
+ {
265
+ "id":"EN7800GTX/2DHTV/256M",
266
+ "name":"ASUS Extreme N7800GTX/2DHTV (256 MB)",
267
+ "manu":"ASUS Computer Inc.",
268
+ "weight":16.0,
269
+ "price":479.95,
270
+ "popularity":7,
271
+ "inStock":false,
272
+ "manufacturedate_dt":"2006-02-13T00:00:00Z",
273
+ "cat":[
274
+ "electronics",
275
+ "graphics card"],
276
+ "features":[
277
+ "NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz",
278
+ "256MB GDDR3 Memory clocked at 1.35GHz",
279
+ "PCI Express x16",
280
+ "Dual DVI connectors, HDTV out, video input",
281
+ "OpenGL 2.0, DirectX 9.0"]},
282
+ {
283
+ "id":"100-435805",
284
+ "name":"ATI Radeon X1900 XTX 512 MB PCIE Video Card",
285
+ "manu":"ATI Technologies",
286
+ "weight":48.0,
287
+ "price":649.99,
288
+ "popularity":7,
289
+ "inStock":false,
290
+ "manufacturedate_dt":"2006-02-13T00:00:00Z",
291
+ "cat":[
292
+ "electronics",
293
+ "graphics card"],
294
+ "features":[
295
+ "ATI RADEON X1900 GPU/VPU clocked at 650MHz",
296
+ "512MB GDDR3 SDRAM clocked at 1.55GHz",
297
+ "PCI Express x16",
298
+ "dual DVI, HDTV, svideo, composite out",
299
+ "OpenGL 2.0, DirectX 9.0"]}]
300
+ }}
@@ -0,0 +1,301 @@
1
+ {
2
+ 'responseHeader'=>{
3
+ 'status'=>0,
4
+ 'QTime'=>1,
5
+ 'params'=>{
6
+ 'indent'=>'on',
7
+ 'start'=>'0',
8
+ 'q'=>'*:*
9
+ ',
10
+ 'wt'=>'ruby',
11
+ 'version'=>'2.2',
12
+ 'rows'=>'100'}},
13
+ 'response'=>{'numFound'=>19,'start'=>0,'docs'=>[
14
+ {
15
+ 'id'=>'SP2514N',
16
+ 'name'=>'Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133',
17
+ 'manu'=>'Samsung Electronics Co. Ltd.',
18
+ 'price'=>92.0,
19
+ 'popularity'=>6,
20
+ 'inStock'=>true,
21
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
22
+ 'cat'=>[
23
+ 'electronics',
24
+ 'hard drive'],
25
+ 'features'=>[
26
+ '7200RPM, 8MB cache, IDE Ultra ATA-133',
27
+ 'NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor']},
28
+ {
29
+ 'id'=>'6H500F0',
30
+ 'name'=>'Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300',
31
+ 'manu'=>'Maxtor Corp.',
32
+ 'price'=>350.0,
33
+ 'popularity'=>6,
34
+ 'inStock'=>true,
35
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
36
+ 'cat'=>[
37
+ 'electronics',
38
+ 'hard drive'],
39
+ 'features'=>[
40
+ 'SATA 3.0Gb/s, NCQ',
41
+ '8.5ms seek',
42
+ '16MB cache']},
43
+ {
44
+ 'id'=>'F8V7067-APL-KIT',
45
+ 'name'=>'Belkin Mobile Power Cord for iPod w/ Dock',
46
+ 'manu'=>'Belkin',
47
+ 'weight'=>4.0,
48
+ 'price'=>19.95,
49
+ 'popularity'=>1,
50
+ 'inStock'=>false,
51
+ 'manufacturedate_dt'=>'2005-08-01T16:30:25Z',
52
+ 'cat'=>[
53
+ 'electronics',
54
+ 'connector'],
55
+ 'features'=>[
56
+ 'car power adapter, white']},
57
+ {
58
+ 'id'=>'IW-02',
59
+ 'name'=>'iPod & iPod Mini USB 2.0 Cable',
60
+ 'manu'=>'Belkin',
61
+ 'weight'=>2.0,
62
+ 'price'=>11.5,
63
+ 'popularity'=>1,
64
+ 'inStock'=>false,
65
+ 'manufacturedate_dt'=>'2006-02-14T23:55:59Z',
66
+ 'cat'=>[
67
+ 'electronics',
68
+ 'connector'],
69
+ 'features'=>[
70
+ 'car power adapter for iPod, white']},
71
+ {
72
+ 'id'=>'MA147LL/A',
73
+ 'name'=>'Apple 60 GB iPod with Video Playback Black',
74
+ 'manu'=>'Apple Computer Inc.',
75
+ 'includes'=>'earbud headphones, USB cable',
76
+ 'weight'=>5.5,
77
+ 'price'=>399.0,
78
+ 'popularity'=>10,
79
+ 'inStock'=>true,
80
+ 'manufacturedate_dt'=>'2005-10-12T08:00:00Z',
81
+ 'cat'=>[
82
+ 'electronics',
83
+ 'music'],
84
+ 'features'=>[
85
+ 'iTunes, Podcasts, Audiobooks',
86
+ 'Stores up to 15,000 songs, 25,000 photos, or 150 hours of video',
87
+ '2.5-inch, 320x240 color TFT LCD display with LED backlight',
88
+ 'Up to 20 hours of battery life',
89
+ 'Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video',
90
+ 'Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication']},
91
+ {
92
+ 'id'=>'TWINX2048-3200PRO',
93
+ 'name'=>'CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail',
94
+ 'manu'=>'Corsair Microsystems Inc.',
95
+ 'price'=>185.0,
96
+ 'popularity'=>5,
97
+ 'inStock'=>true,
98
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
99
+ 'cat'=>[
100
+ 'electronics',
101
+ 'memory'],
102
+ 'features'=>[
103
+ 'CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader']},
104
+ {
105
+ 'id'=>'VS1GB400C3',
106
+ 'name'=>'CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail',
107
+ 'manu'=>'Corsair Microsystems Inc.',
108
+ 'price'=>74.99,
109
+ 'popularity'=>7,
110
+ 'inStock'=>true,
111
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
112
+ 'cat'=>[
113
+ 'electronics',
114
+ 'memory']},
115
+ {
116
+ 'id'=>'VDBDB1A16',
117
+ 'name'=>'A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM',
118
+ 'manu'=>'A-DATA Technology Inc.',
119
+ 'popularity'=>0,
120
+ 'inStock'=>true,
121
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
122
+ 'cat'=>[
123
+ 'electronics',
124
+ 'memory'],
125
+ 'features'=>[
126
+ 'CAS latency 3, 2.7v']},
127
+ {
128
+ 'id'=>'3007WFP',
129
+ 'name'=>'Dell Widescreen UltraSharp 3007WFP',
130
+ 'manu'=>'Dell, Inc.',
131
+ 'includes'=>'USB cable',
132
+ 'weight'=>401.6,
133
+ 'price'=>2199.0,
134
+ 'popularity'=>6,
135
+ 'inStock'=>true,
136
+ 'cat'=>[
137
+ 'electronics',
138
+ 'monitor'],
139
+ 'features'=>[
140
+ '30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast']},
141
+ {
142
+ 'id'=>'VA902B',
143
+ 'name'=>'ViewSonic VA902B - flat panel display - TFT - 19"',
144
+ 'manu'=>'ViewSonic Corp.',
145
+ 'weight'=>190.4,
146
+ 'price'=>279.95,
147
+ 'popularity'=>6,
148
+ 'inStock'=>true,
149
+ 'cat'=>[
150
+ 'electronics',
151
+ 'monitor'],
152
+ 'features'=>[
153
+ '19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution']},
154
+ {
155
+ 'id'=>'0579B002',
156
+ 'name'=>'Canon PIXMA MP500 All-In-One Photo Printer',
157
+ 'manu'=>'Canon Inc.',
158
+ 'weight'=>352.0,
159
+ 'price'=>179.99,
160
+ 'popularity'=>6,
161
+ 'inStock'=>true,
162
+ 'cat'=>[
163
+ 'electronics',
164
+ 'multifunction printer',
165
+ 'printer',
166
+ 'scanner',
167
+ 'copier'],
168
+ 'features'=>[
169
+ 'Multifunction ink-jet color photo printer',
170
+ 'Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi',
171
+ '2.5" color LCD preview screen',
172
+ 'Duplex Copying',
173
+ 'Printing speed up to 29ppm black, 19ppm color',
174
+ 'Hi-Speed USB',
175
+ 'memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard']},
176
+ {
177
+ 'id'=>'TWINX2048-3200PRO-payload',
178
+ 'name'=>'CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail',
179
+ 'manu'=>'Corsair Microsystems Inc.',
180
+ 'price'=>185.0,
181
+ 'popularity'=>5,
182
+ 'inStock'=>true,
183
+ 'payloads'=>'electronics|6.0 memory|3.0',
184
+ 'cat'=>[
185
+ 'electronics',
186
+ 'memory'],
187
+ 'features'=>[
188
+ 'CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader']},
189
+ {
190
+ 'id'=>'VS1GB400C3-payload',
191
+ 'name'=>'CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail',
192
+ 'manu'=>'Corsair Microsystems Inc.',
193
+ 'price'=>74.99,
194
+ 'popularity'=>7,
195
+ 'inStock'=>true,
196
+ 'payloads'=>'electronics|4.0 memory|2.0',
197
+ 'cat'=>[
198
+ 'electronics',
199
+ 'memory']},
200
+ {
201
+ 'id'=>'VDBDB1A16-payload',
202
+ 'name'=>'A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM',
203
+ 'manu'=>'A-DATA Technology Inc.',
204
+ 'popularity'=>5,
205
+ 'inStock'=>true,
206
+ 'payloads'=>'electronics|0.9 memory|0.1',
207
+ 'cat'=>[
208
+ 'electronics',
209
+ 'memory'],
210
+ 'features'=>[
211
+ 'CAS latency 3, 2.7v']},
212
+ {
213
+ 'id'=>'9885A004',
214
+ 'name'=>'Canon PowerShot SD500',
215
+ 'manu'=>'Canon Inc.',
216
+ 'includes'=>'32MB SD card, USB cable, AV cable, battery',
217
+ 'weight'=>6.4,
218
+ 'price'=>329.95,
219
+ 'popularity'=>7,
220
+ 'inStock'=>true,
221
+ 'manufacturedate_dt'=>'2006-02-13T15:26:37Z',
222
+ 'cat'=>[
223
+ 'electronics',
224
+ 'camera'],
225
+ 'features'=>[
226
+ '3x zoop, 7.1 megapixel Digital ELPH',
227
+ 'movie clips up to 640x480 @30 fps',
228
+ '2.0" TFT LCD, 118,000 pixels',
229
+ 'built in flash, red-eye reduction']},
230
+ {
231
+ 'id'=>'SOLR1000',
232
+ 'name'=>'Solr, the Enterprise Search Server',
233
+ 'manu'=>'Apache Software Foundation',
234
+ 'price'=>0.0,
235
+ 'popularity'=>10,
236
+ 'inStock'=>true,
237
+ 'incubationdate_dt'=>'2006-01-17T00:00:00Z',
238
+ 'cat'=>[
239
+ 'software',
240
+ 'search'],
241
+ 'features'=>[
242
+ 'Advanced Full-Text Search Capabilities using Lucene',
243
+ 'Optimized for High Volume Web Traffic',
244
+ 'Standards Based Open Interfaces - XML and HTTP',
245
+ 'Comprehensive HTML Administration Interfaces',
246
+ 'Scalability - Efficient Replication to other Solr Search Servers',
247
+ 'Flexible and Adaptable with XML configuration and Schema',
248
+ 'Good unicode support: héllo (hello with an accent over the e)']},
249
+ {
250
+ 'id'=>'UTF8TEST',
251
+ 'name'=>'Test with some UTF-8 encoded characters',
252
+ 'manu'=>'Apache Software Foundation',
253
+ 'price'=>0.0,
254
+ 'inStock'=>true,
255
+ 'cat'=>[
256
+ 'software',
257
+ 'search'],
258
+ 'features'=>[
259
+ 'No accents here',
260
+ 'This is an e acute: é',
261
+ 'eaiou with circumflexes: êâîôû',
262
+ 'eaiou with umlauts: ëäïöü',
263
+ 'tag with escaped chars: <nicetag/>',
264
+ 'escaped ampersand: Bonnie & Clyde']},
265
+ {
266
+ 'id'=>'EN7800GTX/2DHTV/256M',
267
+ 'name'=>'ASUS Extreme N7800GTX/2DHTV (256 MB)',
268
+ 'manu'=>'ASUS Computer Inc.',
269
+ 'weight'=>16.0,
270
+ 'price'=>479.95,
271
+ 'popularity'=>7,
272
+ 'inStock'=>false,
273
+ 'manufacturedate_dt'=>'2006-02-13T00:00:00Z',
274
+ 'cat'=>[
275
+ 'electronics',
276
+ 'graphics card'],
277
+ 'features'=>[
278
+ 'NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz',
279
+ '256MB GDDR3 Memory clocked at 1.35GHz',
280
+ 'PCI Express x16',
281
+ 'Dual DVI connectors, HDTV out, video input',
282
+ 'OpenGL 2.0, DirectX 9.0']},
283
+ {
284
+ 'id'=>'100-435805',
285
+ 'name'=>'ATI Radeon X1900 XTX 512 MB PCIE Video Card',
286
+ 'manu'=>'ATI Technologies',
287
+ 'weight'=>48.0,
288
+ 'price'=>649.99,
289
+ 'popularity'=>7,
290
+ 'inStock'=>false,
291
+ 'manufacturedate_dt'=>'2006-02-13T00:00:00Z',
292
+ 'cat'=>[
293
+ 'electronics',
294
+ 'graphics card'],
295
+ 'features'=>[
296
+ 'ATI RADEON X1900 GPU/VPU clocked at 650MHz',
297
+ '512MB GDDR3 SDRAM clocked at 1.55GHz',
298
+ 'PCI Express x16',
299
+ 'dual DVI, HDTV, svideo, composite out',
300
+ 'OpenGL 2.0, DirectX 9.0']}]
301
+ }}
data/java_bin.gemspec CHANGED
@@ -5,18 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{java_bin}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kennyj"]
12
- s.date = %q{2010-01-12}
13
- s.description = %q{Solr JavaBin format implementation for Ruby.}
12
+ s.date = %q{2010-01-14}
13
+ s.description = %q{Apache Solr JavaBin format (binary format) implementation for Ruby.}
14
14
  s.email = %q{kennyj@gmail.com}
15
15
  s.extensions = ["ext/java_bin/ext/extconf.rb"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
- "README.rdoc",
19
- "TODO"
18
+ "README.rdoc"
20
19
  ]
21
20
  s.files = [
22
21
  ".document",
@@ -25,14 +24,16 @@ Gem::Specification.new do |s|
25
24
  "LICENSE",
26
25
  "README.rdoc",
27
26
  "Rakefile",
28
- "TODO",
29
27
  "VERSION",
30
28
  "ext/java_bin/ext/extconf.rb",
31
29
  "ext/java_bin/ext/parser.c",
32
30
  "ext/java_bin/ext/parser.h",
33
31
  "fixtures/javabin.dat",
32
+ "fixtures/javabin2.dat",
34
33
  "fixtures/json.dat",
34
+ "fixtures/json2.dat",
35
35
  "fixtures/ruby.dat",
36
+ "fixtures/ruby2.dat",
36
37
  "java_bin.gemspec",
37
38
  "lib/java_bin.rb",
38
39
  "lib/java_bin/ext.rb",
@@ -40,6 +41,8 @@ Gem::Specification.new do |s|
40
41
  "lib/java_bin/pure.rb",
41
42
  "lib/java_bin/pure/parser.rb",
42
43
  "lib/java_bin/version.rb",
44
+ "lib/rsolr_support.rb",
45
+ "lib/solr_ruby_support.rb",
43
46
  "test/helper.rb",
44
47
  "test/test_java_bin_parser.rb",
45
48
  "test/xxx_performance.rb"
@@ -48,10 +51,10 @@ Gem::Specification.new do |s|
48
51
  s.rdoc_options = ["--charset=UTF-8"]
49
52
  s.require_paths = ["lib", "ext"]
50
53
  s.rubygems_version = %q{1.3.5}
51
- s.summary = %q{Solr JavaBin format implementation for Ruby.}
54
+ s.summary = %q{Apache Solr JavaBin format implementation for Ruby.}
52
55
  s.test_files = [
53
- "test/xxx_performance.rb",
54
- "test/test_java_bin_parser.rb",
56
+ "test/test_java_bin_parser.rb",
57
+ "test/xxx_performance.rb",
55
58
  "test/helper.rb"
56
59
  ]
57
60
 
data/lib/java_bin.rb CHANGED
@@ -15,3 +15,8 @@ module JavaBin
15
15
  end
16
16
 
17
17
  end
18
+
19
+ # monkey patching
20
+ require "rsolr_support"
21
+ require "solr_ruby_support"
22
+
@@ -0,0 +1,24 @@
1
+ # RSolr support
2
+
3
+ if defined? RSolr::Client
4
+
5
+ class RSolr::Client
6
+ protected
7
+
8
+ def map_params(params)
9
+ params ||= {}
10
+ {:wt=>:javabin}.merge(params)
11
+ end
12
+
13
+ def adapt_response_with_java_bin(connection_response)
14
+ data = adapt_response_without_java_bin(connection_response)
15
+ data = JavaBin.parser.new.parse(data) if data.raw[:params][:wt] == :javabin
16
+ data
17
+ end
18
+
19
+ alias_method :adapt_response_without_java_bin, :adapt_response
20
+ alias_method :adapt_response, :adapt_response_with_java_bin
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,93 @@
1
+ # Solr-Ruby support
2
+
3
+ # solr-ruby request class hierarchy
4
+ #
5
+ # base
6
+ # ping
7
+ # update
8
+ # add_document
9
+ # commit
10
+ # delete
11
+ # modify_document
12
+ # optimize
13
+ # select => :response_format, :to_hash
14
+ # index_info
15
+ # standard
16
+ # dismax
17
+ # spellcheck
18
+ #
19
+ # solr-ruby response class hierarchy
20
+ #
21
+ # base => :make_response
22
+ # xml
23
+ # add_document
24
+ # commit
25
+ # optimize
26
+ # delete
27
+ # modify_document
28
+ # ping
29
+ # ruby => :initialize
30
+ # index_info
31
+ # select
32
+ # spellcheck
33
+ # standard
34
+ # dismax
35
+
36
+ if defined? Solr::Request::Base
37
+
38
+ class Solr::Request::Select
39
+ def response_format
40
+ :javabin
41
+ end
42
+ def to_hash
43
+ return {:qt => query_type, :wt => 'javabin'}.merge(@select_params)
44
+ end
45
+ end
46
+
47
+ class Solr::Response::Base
48
+ def self.make_response(request, raw)
49
+
50
+ # make sure response format seems sane
51
+ unless [:xml, :ruby, :javabin].include?(request.response_format)
52
+ raise Solr::Exception.new("unknown response format: #{request.response_format}" )
53
+ end
54
+
55
+ # TODO: Factor out this case... perhaps the request object should provide the response class instead? Or dynamically align by class name?
56
+ # Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object?
57
+
58
+ begin
59
+ klass = eval(request.class.name.sub(/Request/,'Response'))
60
+ rescue NameError
61
+ raise Solr::Exception.new("unknown request type: #{request.class}")
62
+ else
63
+ klass.new(raw)
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ # FIXME. I should create Solr::Response::JavaBin class,
71
+ # but response class hierarchy doesn't permit it ! (kennyj)
72
+ class Solr::Response::Ruby < Solr::Response::Base
73
+ def initialize(java_bin_data)
74
+ super
75
+ begin
76
+ #TODO: what about pulling up data/header/response to ResponseBase,
77
+ # or maybe a new middle class like SelectResponseBase since
78
+ # all Select queries return this same sort of stuff??
79
+ # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure.
80
+ # a goal of solrb is to make it irrelevant which gets used under the hood,
81
+ # but favor Ruby responses.
82
+ @data = ::JavaBin.parser.new.parse(java_bin_data)
83
+ @header = @data['responseHeader']
84
+ raise "response should be a hash" unless @data.kind_of? Hash
85
+ raise "response header missing" unless @header.kind_of? Hash
86
+ rescue SyntaxError => e
87
+ raise Solr::Exception.new("invalid java bin data: #{e}")
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+
@@ -66,14 +66,31 @@ class TestJavaBinParser < Test::Unit::TestCase
66
66
  assert_equal result['response']['docs'][1]['score'], 0.5030758380889893
67
67
  end
68
68
 
69
+ def test_javabin2_dat
70
+ result = @parser.parse(open("fixtures/javabin2.dat", "r:utf-8").read)
71
+ assert_equal 19, result['response']['docs'].size
72
+ end
73
+
74
+
69
75
  TIMES = 5000
70
76
  def test_javabin_parse_and_ruby_eval
71
- jb = open("fixtures/javabin.dat", "r:utf-8").read
72
77
  r = open("fixtures/ruby.dat", "r:utf-8").read
78
+ jb = open("fixtures/javabin.dat", "r:utf-8").read
73
79
  puts ""
74
80
  r_et = elapsed_time("ruby eval parse. ", TIMES) { eval(r) }
75
81
  jb_et = elapsed_time("javabin parse. ", TIMES) { @parser.parse(jb) }
76
- assert (jb_et * 2) < r_et if @parser.is_a? JavaBin::Ext::Parser
82
+ puts("#{r_et/jb_et} times")
83
+ assert (jb_et * 2.5) < r_et if @parser.is_a? JavaBin::Ext::Parser
84
+ end
85
+
86
+ def test_javabin2_parse_and_ruby2_eval
87
+ r = open("fixtures/ruby2.dat", "r:utf-8").read
88
+ jb = open("fixtures/javabin2.dat", "r:utf-8").read
89
+ puts ""
90
+ r_et = elapsed_time("ruby2 eval parse. ", TIMES) { eval(r) }
91
+ jb_et = elapsed_time("javabin2 parse. ", TIMES) { @parser.parse(jb) }
92
+ puts("#{r_et/jb_et} times")
93
+ assert (jb_et * 2.5) < r_et if @parser.is_a? JavaBin::Ext::Parser
77
94
  end
78
95
 
79
96
  def test_memory_allocate
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: java_bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kennyj
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-12 00:00:00 +09:00
12
+ date: 2010-01-14 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Solr JavaBin format implementation for Ruby.
16
+ description: Apache Solr JavaBin format (binary format) implementation for Ruby.
17
17
  email: kennyj@gmail.com
18
18
  executables: []
19
19
 
@@ -22,7 +22,6 @@ extensions:
22
22
  extra_rdoc_files:
23
23
  - LICENSE
24
24
  - README.rdoc
25
- - TODO
26
25
  files:
27
26
  - .document
28
27
  - .gitignore
@@ -30,14 +29,16 @@ files:
30
29
  - LICENSE
31
30
  - README.rdoc
32
31
  - Rakefile
33
- - TODO
34
32
  - VERSION
35
33
  - ext/java_bin/ext/extconf.rb
36
34
  - ext/java_bin/ext/parser.c
37
35
  - ext/java_bin/ext/parser.h
38
36
  - fixtures/javabin.dat
37
+ - fixtures/javabin2.dat
39
38
  - fixtures/json.dat
39
+ - fixtures/json2.dat
40
40
  - fixtures/ruby.dat
41
+ - fixtures/ruby2.dat
41
42
  - java_bin.gemspec
42
43
  - lib/java_bin.rb
43
44
  - lib/java_bin/ext.rb
@@ -45,6 +46,8 @@ files:
45
46
  - lib/java_bin/pure.rb
46
47
  - lib/java_bin/pure/parser.rb
47
48
  - lib/java_bin/version.rb
49
+ - lib/rsolr_support.rb
50
+ - lib/solr_ruby_support.rb
48
51
  - test/helper.rb
49
52
  - test/test_java_bin_parser.rb
50
53
  - test/xxx_performance.rb
@@ -76,8 +79,8 @@ rubyforge_project:
76
79
  rubygems_version: 1.3.5
77
80
  signing_key:
78
81
  specification_version: 3
79
- summary: Solr JavaBin format implementation for Ruby.
82
+ summary: Apache Solr JavaBin format implementation for Ruby.
80
83
  test_files:
81
- - test/xxx_performance.rb
82
84
  - test/test_java_bin_parser.rb
85
+ - test/xxx_performance.rb
83
86
  - test/helper.rb
data/TODO DELETED
@@ -1,13 +0,0 @@
1
- * ChangeLogを準備
2
- * 他のgemの依存関係
3
- ** rsolr/solr-rubyのmonkey-patch
4
- * hashのキーをsymbolにする
5
- * Windowsでのビルド確認
6
- * ドキュメント
7
- * LGPLとの関係を確認する
8
- * testcaseの充実
9
- ** 容量の大きい場合
10
- ** ruby 1.8.x/1.9.xでの互換性維持
11
- * builder(writer)作成
12
- * JRuby support
13
-