rroonga 2.1.2 → 2.1.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.
- data/doc/text/news.textile +29 -0
- data/doc/text/tutorial.textile +176 -199
- data/ext/groonga/extconf.rb +16 -2
- data/ext/groonga/rb-grn-logger.c +214 -202
- data/ext/groonga/rb-grn-object.c +1 -23
- data/ext/groonga/rb-grn-table-cursor.c +1 -2
- data/ext/groonga/rb-grn-table.c +1 -2
- data/ext/groonga/rb-grn-utils.c +3 -7
- data/ext/groonga/rb-grn.h +2 -16
- data/ext/groonga/rb-groonga.c +1 -3
- data/lib/groonga.rb +2 -1
- data/lib/groonga/context.rb +27 -0
- data/lib/groonga/dumper.rb +35 -3
- data/lib/groonga/logger.rb +142 -0
- data/rroonga-build.rb +2 -2
- data/test/groonga-test-utils.rb +3 -1
- data/test/test-context.rb +63 -0
- data/test/test-logger.rb +1 -0
- metadata +292 -307
- data/ext/groonga/rb-grn-view-accessor.c +0 -53
- data/ext/groonga/rb-grn-view-cursor.c +0 -35
- data/ext/groonga/rb-grn-view-record.c +0 -41
- data/ext/groonga/rb-grn-view.c +0 -414
- data/test/test-schema-view.rb +0 -90
- data/test/test-view.rb +0 -71
data/doc/text/news.textile
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
h1. NEWS
|
2
2
|
|
3
|
+
h2(#2-1-3). 2.1.3: 2013-01-29
|
4
|
+
|
5
|
+
h3. Improvements
|
6
|
+
|
7
|
+
* Removed Groonga::View removed in groonga 2.1.2.
|
8
|
+
* [doc] Added tutorial in English.
|
9
|
+
** for English:http://ranguba.org/rroonga/en/file.tutorial.html
|
10
|
+
** for Japanese:http://ranguba.org/rroonga/ja/file.tutorial.html
|
11
|
+
* [context] Added Context#restore. This method restores command dumped
|
12
|
+
by "grndump" command. Please see example below:
|
13
|
+
<pre>
|
14
|
+
!!!ruby
|
15
|
+
dumped_commands = File.read("dump.grn")
|
16
|
+
context.restore(dumped_commands)
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
h3. Fixes
|
20
|
+
|
21
|
+
* Added missing Groonga::Logger.
|
22
|
+
* [dumper] Reduced needless new lines in dumped commands.
|
23
|
+
* For installing groonga with this gem:
|
24
|
+
** Fix the needless install of documents.
|
25
|
+
** Fix the needless build of static library.
|
26
|
+
|
27
|
+
* For ranguba project:
|
28
|
+
** [template] Removed needless block for sponsor by rubyforge.
|
29
|
+
** [template] Removed needless piwik tag.
|
30
|
+
** [template] Fixed URLs of references in Japanese.
|
31
|
+
|
3
32
|
h2(#2-1-2). 2.1.2: 2013-01-04
|
4
33
|
|
5
34
|
h3. Fixes
|
data/doc/text/tutorial.textile
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
h1.
|
1
|
+
h1. Tutorial
|
2
2
|
|
3
|
-
|
4
|
-
rroongaの操作方法を紹介します。
|
3
|
+
This page introduce how to use rroonga via a simple application making.
|
5
4
|
|
6
|
-
h2.
|
5
|
+
h2. Install
|
7
6
|
|
8
|
-
rroonga
|
7
|
+
You can install rroonga in your compter with RubyGems.
|
9
8
|
|
10
9
|
<pre>
|
11
10
|
!!!command_line
|
12
11
|
% sudo gem install rroonga
|
13
12
|
</pre>
|
14
13
|
|
15
|
-
h2.
|
14
|
+
h2. Create Database
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
す。
|
16
|
+
Let's create database for simple bookmark application.
|
17
|
+
Please execute irb with loading rroonga with this command:
|
20
18
|
|
21
19
|
<pre>
|
22
20
|
!!!irb
|
@@ -24,7 +22,7 @@ h2. データベースの作成
|
|
24
22
|
>>
|
25
23
|
</pre>
|
26
24
|
|
27
|
-
|
25
|
+
Now you use UTF-8 as the encoding of database.
|
28
26
|
|
29
27
|
<pre>
|
30
28
|
!!!irb
|
@@ -34,7 +32,7 @@ h2. データベースの作成
|
|
34
32
|
=> {:encoding=>:utf8}
|
35
33
|
</pre>
|
36
34
|
|
37
|
-
|
35
|
+
Then, try to create database in a file.
|
38
36
|
|
39
37
|
<pre>
|
40
38
|
!!!irb
|
@@ -42,33 +40,38 @@ h2. データベースの作成
|
|
42
40
|
=> #<Groonga::Database ...>
|
43
41
|
</pre>
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
せん。
|
43
|
+
From now, the created database is used implicitly.
|
44
|
+
You don't have to be aware of it after you created a database first.
|
48
45
|
|
49
|
-
h2.
|
46
|
+
h2. Define table
|
50
47
|
|
51
|
-
|
48
|
+
Groonga supports 4 types of tables.
|
52
49
|
|
53
50
|
- Groonga::Hash :=
|
54
|
-
|
55
|
-
|
51
|
+
Hash table. It manages records via each primary key. It supports
|
52
|
+
very quickly exact match search.
|
56
53
|
=:
|
57
54
|
|
58
55
|
- Groonga::PatriciaTrie :=
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
Patricia Trie. It supports some search such as predictive search and
|
57
|
+
common prefix search, but it provides a little slowly exact match search
|
58
|
+
than Groonga::Hash. It provides cursor to take records in ascending
|
59
|
+
or descending order.
|
60
|
+
=:
|
61
|
+
|
62
|
+
- Groonga::DoubleArrayTrie :=
|
63
|
+
Double Array Trie. It requires large spaces rather than other
|
64
|
+
tables, but it can update key without ID change. It provides exract
|
65
|
+
match search, predictive search and common prefix search and cursor
|
66
|
+
like Groonga::PatriciaTrie.
|
63
67
|
=:
|
64
68
|
|
65
69
|
- Groonga::Array :=
|
66
|
-
|
67
|
-
識別します。
|
70
|
+
Array. It doesn't have primary keys. It manages records by ID.
|
68
71
|
=:
|
69
72
|
|
70
|
-
|
71
|
-
|
73
|
+
Now, you use Groonga::Hash and create the table named @Items@. The type
|
74
|
+
of its primary key is String.
|
72
75
|
|
73
76
|
<pre>
|
74
77
|
!!!irb
|
@@ -76,9 +79,8 @@ groongaには以下の3種類のテーブルがあります。
|
|
76
79
|
=> [...]
|
77
80
|
</pre>
|
78
81
|
|
79
|
-
|
80
|
-
|
81
|
-
定義したテーブルはGroonga.[]で参照できます。
|
82
|
+
You have @Items@ table by this code.
|
83
|
+
You can refer the defined table with Groonga.[] like below:
|
82
84
|
|
83
85
|
<pre>
|
84
86
|
!!!irb
|
@@ -86,10 +88,9 @@ groongaには以下の3種類のテーブルがあります。
|
|
86
88
|
=> #<Groonga::Hash ...>
|
87
89
|
</pre>
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
の件数を取得できます。
|
91
|
+
You can treat it like Hash.
|
92
|
+
For example, let's type @items.size@ to get the number of records in
|
93
|
+
the table.
|
93
94
|
|
94
95
|
<pre>
|
95
96
|
!!!irb
|
@@ -97,19 +98,19 @@ groongaには以下の3種類のテーブルがあります。
|
|
97
98
|
=> 0
|
98
99
|
</pre>
|
99
100
|
|
100
|
-
h2.
|
101
|
+
h2. Add records
|
101
102
|
|
102
|
-
@Items@
|
103
|
+
Let's add records to @Items@ table.
|
103
104
|
|
104
105
|
<pre>
|
105
106
|
!!!irb
|
106
|
-
>> items.add("http://
|
107
|
+
>> items.add("http://en.wikipedia.org/wiki/Ruby")
|
107
108
|
=> #<Groonga::Record ...>
|
108
|
-
>> items.add("http://www.ruby-lang.org/
|
109
|
+
>> items.add("http://www.ruby-lang.org/")
|
109
110
|
=> #<Groonga::Record ...>
|
110
111
|
</pre>
|
111
112
|
|
112
|
-
|
113
|
+
Please check the number of records. It increases from 0 to 2.
|
113
114
|
|
114
115
|
<pre>
|
115
116
|
!!!irb
|
@@ -117,22 +118,19 @@ h2. レコードを追加する
|
|
117
118
|
=> 2
|
118
119
|
</pre>
|
119
120
|
|
120
|
-
|
121
|
+
If you can get record by primary key, type like below:
|
121
122
|
|
122
123
|
<pre>
|
123
124
|
!!!irb
|
124
|
-
>> items["http://
|
125
|
+
>> items["http://en.wikipedia.org/wiki/Ruby"]
|
125
126
|
=> #<Groonga::Record ...>
|
126
127
|
</pre>
|
127
128
|
|
128
|
-
h2.
|
129
|
+
h2. Full text search
|
129
130
|
|
130
|
-
|
131
|
-
ましょう。
|
131
|
+
Let's add item's title to full text search.
|
132
132
|
|
133
|
-
|
134
|
-
ます。ここでは、 @Text@ 型のデータを持つカラムとして定義
|
135
|
-
します。
|
133
|
+
first, you add the @Text@ type column "@title@" to @Items@ table.
|
136
134
|
|
137
135
|
<pre>
|
138
136
|
!!!irb
|
@@ -142,8 +140,8 @@ h2. 全文検索を行う
|
|
142
140
|
=> [...]
|
143
141
|
</pre>
|
144
142
|
|
145
|
-
|
146
|
-
|
143
|
+
Defined columns is named as @#{TABLE_NAME}.#{COLUMN_NAME}@.
|
144
|
+
You can refer them with {Groonga.[]} as same as tables.
|
147
145
|
|
148
146
|
<pre>
|
149
147
|
!!!irb
|
@@ -151,35 +149,33 @@ h2. 全文検索を行う
|
|
151
149
|
=> #<Groonga::VariableSizeColumn ...>
|
152
150
|
</pre>
|
153
151
|
|
154
|
-
|
155
|
-
|
156
|
-
|
152
|
+
|
153
|
+
Secondly, let's add the table containing terms from splited from texts.
|
154
|
+
Then you define the @Terms@ for it.
|
157
155
|
|
158
156
|
<pre>
|
159
157
|
!!!irb
|
160
158
|
>> Groonga::Schema.create_table("Terms",
|
161
159
|
?> :type => :patricia_trie,
|
162
|
-
?> :
|
160
|
+
?> :normalizer => :NormalizerAuto,
|
163
161
|
?> :default_tokenizer => "TokenBigram")
|
164
162
|
</pre>
|
165
163
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
164
|
+
You specify @:default_tokenzier => "TokenBigram"@ for "Tokenizer" in
|
165
|
+
the above code.
|
166
|
+
"Tokenizer" is the object to split terms from texts. The default value
|
167
|
+
for it is none.
|
168
|
+
Full text search requires a tokenizer, so you specify "Bigram", a type
|
169
|
+
of N-gram.
|
170
|
+
Full text search with N-gram uses splited N characters and their
|
171
|
+
position in texts. "N" in N-gram specifies the number of each terms.
|
172
|
+
Groonga supports Unigram (N=1), Bigram (N=2) and Trigram (N=3).
|
172
173
|
|
173
|
-
|
174
|
-
|
175
|
-
るかの文字数になります。groongaは1文字で分解するユニグラム、
|
176
|
-
2文字のバイグラム、3文字のトリグラムをサポートしています。
|
174
|
+
You also specify @:normalizer => :NormalizerAuto@ to search texts with
|
175
|
+
ignoring the case.
|
177
176
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
単語格納用テーブルの準備ができたので、 @Items@ テーブ
|
182
|
-
ルの @title@ カラムに対するインデックスを定義します。
|
177
|
+
Now, you ready table for terms, so you define the index of
|
178
|
+
@Items.tiltle@ column.
|
183
179
|
|
184
180
|
<pre>
|
185
181
|
!!!irb
|
@@ -189,74 +185,67 @@ N-gramを利用した全文検索では、分解したN文字とその出現位
|
|
189
185
|
=> [...]
|
190
186
|
</pre>
|
191
187
|
|
192
|
-
|
193
|
-
|
194
|
-
ラムとして定義します。
|
188
|
+
You may feel a few unreasonable code. The index of @Items@ table's
|
189
|
+
column is defined as the column in @Terms@.
|
195
190
|
|
196
|
-
@Items
|
197
|
-
|
198
|
-
うになります。
|
191
|
+
When a record is added to @Items@, groonga adds records associated
|
192
|
+
each terms in it to @Terms@ automatically.
|
199
193
|
|
200
|
-
@Terms@ は、文書に含まれる語彙に相当する、やや特殊な
|
201
|
-
テーブルだと言えます。しかし、他のテーブルと同様に語彙テーブ
|
202
|
-
ルには自由にカラムを追加し、単語毎の様々な属性を管理すること
|
203
|
-
ができます。これはある種の検索処理を行う際には非常に便利に機
|
204
|
-
能します。
|
205
194
|
|
206
|
-
|
195
|
+
@Terms@ is a few particular table, but you can add some columns to term
|
196
|
+
table such as @Terms@ and manage many attributes of each terms. It is
|
197
|
+
very useful to process particular search.
|
207
198
|
|
208
|
-
|
199
|
+
Now, you finished table definition.
|
200
|
+
Let's put some values to @title@ of each record you added before.
|
209
201
|
|
210
202
|
<pre>
|
211
203
|
!!!irb
|
212
|
-
>> items["http://
|
204
|
+
>> items["http://en.wikipedia.org/wiki/Ruby"].title = "Ruby"
|
213
205
|
=> "Ruby"
|
214
|
-
>> items["http://www.ruby-lang.org/
|
215
|
-
"
|
206
|
+
>> items["http://www.ruby-lang.org/"].title = "Ruby Programming Language"
|
207
|
+
"Ruby Programming Language"
|
216
208
|
</pre>
|
217
209
|
|
218
|
-
|
210
|
+
Now, you can do full text search like above:
|
219
211
|
|
220
212
|
<pre>
|
221
213
|
!!!irb
|
222
214
|
>> ruby_items = items.select {|record| record.title =~ "Ruby"}
|
223
|
-
=> #<Groonga::Hash ...,
|
215
|
+
=> #<Groonga::Hash ..., normalizer: (nil)>
|
224
216
|
</pre>
|
225
217
|
|
226
|
-
|
227
|
-
|
218
|
+
Groonga returns the search result as Groonga::Hash.
|
219
|
+
Keys in this hash table is records of hitted @Items@.
|
228
220
|
|
229
221
|
<pre>
|
230
222
|
!!!irb
|
231
223
|
>> ruby_items.collect {|record| record.key.key}
|
232
|
-
=> ["http://
|
224
|
+
=> ["http://en.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
|
233
225
|
</pre>
|
234
226
|
|
235
|
-
|
236
|
-
|
237
|
-
のキーを返しています。
|
227
|
+
In above example, you get records in @Items@ with @record.key@, and
|
228
|
+
keys of them with @record.key.key@.
|
238
229
|
|
239
|
-
@record["_key"]
|
240
|
-
を辿っていき、参照先のキーにアクセスできます。
|
230
|
+
You can access a refered key in records briefly with @record["_key"]@.
|
241
231
|
|
242
232
|
<pre>
|
243
233
|
!!!irb
|
244
234
|
>> ruby_items.collect {|record| record["_key"]}
|
245
|
-
=> ["http://
|
235
|
+
=> ["http://en.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
|
246
236
|
</pre>
|
247
237
|
|
248
|
-
h2.
|
238
|
+
h2. Improve the simple bookmark application
|
249
239
|
|
250
|
-
|
251
|
-
|
252
|
-
|
240
|
+
Let's try to improve this simple application a little. You can create
|
241
|
+
bookmark application for multi users and they can comment to each
|
242
|
+
bookmarks.
|
253
243
|
|
254
|
-
|
255
|
-
下図のようなテーブル構成にします。
|
244
|
+
First, you add tables for users and for comments like below:
|
256
245
|
|
257
246
|
!http://qwik.jp/senna/senna2.files/rect4605.png!
|
258
247
|
|
259
|
-
|
248
|
+
Let's add the table for users, @Users@.
|
260
249
|
|
261
250
|
<pre>
|
262
251
|
!!!irb
|
@@ -266,7 +255,8 @@ h2. マルチユーザ向けのブックマークアプリケーション
|
|
266
255
|
=> [...]
|
267
256
|
</pre>
|
268
257
|
|
269
|
-
|
258
|
+
|
259
|
+
Next, let's add the table for comments as @Comments@.
|
270
260
|
|
271
261
|
<pre>
|
272
262
|
!!!irb
|
@@ -279,8 +269,8 @@ h2. マルチユーザ向けのブックマークアプリケーション
|
|
279
269
|
=> [...]
|
280
270
|
</pre>
|
281
271
|
|
282
|
-
@
|
283
|
-
|
272
|
+
Then you define the index of @content@ column in @Comments@ for full
|
273
|
+
text search.
|
284
274
|
|
285
275
|
<pre>
|
286
276
|
!!!irb
|
@@ -290,46 +280,43 @@ h2. マルチユーザ向けのブックマークアプリケーション
|
|
290
280
|
=> [...]
|
291
281
|
</pre>
|
292
282
|
|
293
|
-
|
283
|
+
You finish table definition by above code.
|
294
284
|
|
295
|
-
|
285
|
+
Secondly, you add some users to @Users@.
|
296
286
|
|
297
287
|
<pre>
|
298
288
|
!!!irb
|
299
289
|
>> users = Groonga["Users"]
|
300
290
|
=> #<Groonga::Hash ...>
|
301
|
-
>> users.add("
|
291
|
+
>> users.add("alice", :name => "Alice")
|
302
292
|
=> #<Groonga::Record ...>
|
303
|
-
>> users.add("
|
293
|
+
>> users.add("bob", :name => "Bob")
|
304
294
|
=> #<Groonga::Record ...>
|
305
295
|
</pre>
|
306
296
|
|
307
|
-
|
308
|
-
|
297
|
+
Now, let's write the process to bookmark by a user.
|
298
|
+
You assume that the user, @moritan@, bookmark a page including
|
299
|
+
infomation related Ruby.
|
309
300
|
|
310
|
-
|
311
|
-
想定します。
|
312
|
-
|
313
|
-
まず対象のページが @Items@ テーブルに登録済かどうか調
|
314
|
-
べます。
|
301
|
+
First, you check if the page has been added @Items@ already.
|
315
302
|
|
316
303
|
<pre>
|
317
304
|
!!!irb
|
318
|
-
>> items.has_key?("http://www.
|
305
|
+
>> items.has_key?("http://www.ruby-doc.org/")
|
319
306
|
=> false
|
320
307
|
</pre>
|
321
308
|
|
322
|
-
|
309
|
+
The page hasn't been added, so you add it to @Items@.
|
323
310
|
|
324
311
|
<pre>
|
325
312
|
!!!irb
|
326
|
-
>> items.add("http://www.
|
327
|
-
?> :title => "
|
313
|
+
>> items.add("http://www.ruby-doc.org/",
|
314
|
+
?> :title => "Ruby-Doc.org: Documenting the Ruby Language")
|
328
315
|
=> #<Groonga::Record ...>
|
329
316
|
</pre>
|
330
317
|
|
331
|
-
|
332
|
-
@
|
318
|
+
Next, you add the record to @Comments@. This record contains this page
|
319
|
+
as its @item@ column.
|
333
320
|
|
334
321
|
<pre>
|
335
322
|
!!!irb
|
@@ -337,16 +324,16 @@ h2. マルチユーザ向けのブックマークアプリケーション
|
|
337
324
|
=> true
|
338
325
|
>> comments = Groonga["Comments"]
|
339
326
|
=> #<Groonga::Array ...>
|
340
|
-
>> comments.add(:item => "http://www.
|
341
|
-
?> :author => "
|
342
|
-
?> :content => "Ruby
|
327
|
+
>> comments.add(:item => "http://www.ruby-doc.org/",
|
328
|
+
?> :author => "alice",
|
329
|
+
?> :content => "Ruby documents",
|
343
330
|
?> :issued => Time.parse("2010-11-20T18:01:22+09:00"))
|
344
331
|
=> #<Groonga::Record ...>
|
345
332
|
</pre>
|
346
333
|
|
347
|
-
h2.
|
334
|
+
h2. Define methods for this process
|
348
335
|
|
349
|
-
|
336
|
+
For usefull, you define methods for above processes.
|
350
337
|
|
351
338
|
<pre>
|
352
339
|
!!!irb
|
@@ -364,38 +351,37 @@ h2. メソッド化
|
|
364
351
|
=> nil
|
365
352
|
</pre>
|
366
353
|
|
367
|
-
@items@
|
368
|
-
|
354
|
+
You assign @items@ and @comments@ to each instance variable, so you can
|
355
|
+
use them in @add_bookmark@ method.
|
369
356
|
|
370
|
-
@add_bookmark@
|
357
|
+
@add_bookmark@ executes processes like below:
|
371
358
|
|
372
|
-
*
|
373
|
-
*
|
374
|
-
*
|
359
|
+
* Check if the record associated the page exists in @Items@ table.
|
360
|
+
* If not, add the record to it.
|
361
|
+
* Add the record to @Comments@ table.
|
375
362
|
|
376
|
-
|
377
|
-
ましょう。
|
363
|
+
With this method, lets bookmark some pages.
|
378
364
|
|
379
365
|
<pre>
|
380
366
|
!!!irb
|
381
|
-
>> add_bookmark("
|
382
|
-
?> "
|
367
|
+
>> add_bookmark("https://rubygems.org/",
|
368
|
+
?> "RubyGems.org | your community gem host", "alice", "Ruby gems",
|
383
369
|
?> Time.parse("2010-10-07T14:18:28+09:00"))
|
384
370
|
=> #<Groonga::Record ...>
|
385
|
-
>> add_bookmark("http://
|
386
|
-
?> "Ruby
|
387
|
-
?> "Ruby groonga
|
371
|
+
>> add_bookmark("http://ranguba.org/",
|
372
|
+
?> "Fulltext search by Ruby with groonga - Ranguba", "bob",
|
373
|
+
?> "Ruby groonga fulltextsearch",
|
388
374
|
?> Time.parse("2010-11-11T12:39:59+09:00"))
|
389
375
|
=> #<Groonga::Record ...>
|
390
|
-
>> add_bookmark("http://www.
|
391
|
-
?> "
|
376
|
+
>> add_bookmark("http://www.ruby-doc.org/",
|
377
|
+
?> "ruby-doc", "bob", "ruby documents",
|
392
378
|
?> Time.parse("2010-07-28T20:46:23+09:00"))
|
393
379
|
=> #<Groonga::Record ...>
|
394
380
|
</pre>
|
395
381
|
|
396
|
-
h2.
|
382
|
+
h2. Full text search part 2
|
397
383
|
|
398
|
-
|
384
|
+
Let's do full text search for added records.
|
399
385
|
|
400
386
|
<pre>
|
401
387
|
!!!irb
|
@@ -404,28 +390,26 @@ h2. 全文検索その2
|
|
404
390
|
>> end
|
405
391
|
=> #<Groonga::Hash ...>
|
406
392
|
>> records.each do |record|
|
407
|
-
?> comment = record
|
393
|
+
?> comment = record
|
408
394
|
>> p [comment.id,
|
409
395
|
?> comment.issued,
|
410
396
|
?> comment.item.title,
|
411
397
|
?> comment.author.name,
|
412
398
|
?> comment.content]
|
413
399
|
>> end
|
414
|
-
[1,
|
415
|
-
[2,
|
416
|
-
[3,
|
417
|
-
[4,
|
400
|
+
[1, 2010-11-20 18:01:22 +0900, "Ruby-Doc.org: Documenting the Ruby Language", "Alice", "Ruby documents"]
|
401
|
+
[2, 2010-10-07 14:18:28 +0900, "RubyGems.org | your community gem host", "Alice", "Ruby gems"]
|
402
|
+
[3, 2010-11-11 12:39:59 +0900, "Fulltext search by Ruby with groonga - Ranguba", "Bob", "Ruby groonga fulltextsearch"]
|
403
|
+
[4, 2010-07-28 20:46:23 +0900, "Ruby-Doc.org: Documenting the Ruby Language", "Bob", "ruby documents"]
|
418
404
|
</pre>
|
419
405
|
|
420
|
-
|
421
|
-
|
422
|
-
RDB
|
423
|
-
@
|
424
|
-
必要になります。)
|
406
|
+
You can access the columns with the same name method as each them.
|
407
|
+
These methods suport to access the complex data type.
|
408
|
+
(In usually RDB, you should namage JOIN tables, @Items@, @Comments@,
|
409
|
+
@Users@.)
|
425
410
|
|
426
|
-
|
427
|
-
|
428
|
-
れています。
|
411
|
+
The search is finished when the first sentence in this codes. The
|
412
|
+
results of this search is the object as records set.
|
429
413
|
|
430
414
|
<pre>
|
431
415
|
!!!irb
|
@@ -433,29 +417,27 @@ RDBで実現するためには、 @Items@ テーブル、
|
|
433
417
|
#<Groonga::Hash ..., size: <4>>
|
434
418
|
</pre>
|
435
419
|
|
436
|
-
|
437
|
-
|
438
|
-
以下は、日付で降順にソートしてから出力した例です。
|
420
|
+
You can arrange this records set before output.
|
421
|
+
For example, sort these records in the descending order by date.
|
439
422
|
|
440
423
|
<pre>
|
441
424
|
!!!irb
|
442
425
|
>> records.sort([{:key => "issued", :order => "descending"}]).each do |record|
|
443
|
-
?> comment = record
|
426
|
+
?> comment = record
|
444
427
|
>> p [comment.id,
|
445
428
|
?> comment.issued,
|
446
429
|
?> comment.item.title,
|
447
430
|
?> comment.author.name,
|
448
431
|
?> comment.content]
|
449
432
|
>> end
|
450
|
-
[1,
|
451
|
-
[
|
452
|
-
[
|
453
|
-
[4,
|
433
|
+
[1, 2010-11-20 18:01:22 +0900, "Ruby-Doc.org: Documenting the Ruby Language", "Alice", "Ruby documents"]
|
434
|
+
[2, 2010-11-11 12:39:59 +0900, "Fulltext search by Ruby with groonga - Ranguba", "Bob", "Ruby groonga fulltextsearch"]
|
435
|
+
[3, 2010-10-07 14:18:28 +0900, "RubyGems.org | your community gem host", "Alice", "Ruby gems"]
|
436
|
+
[4, 2010-07-28 20:46:23 +0900, "Ruby-Doc.org: Documenting the Ruby Language", "Bob", "ruby documents"]
|
454
437
|
=> [...]
|
455
438
|
</pre>
|
456
439
|
|
457
|
-
|
458
|
-
ループ化してみます。
|
440
|
+
Let's group the result by each item for easy view.
|
459
441
|
|
460
442
|
<pre>
|
461
443
|
!!!irb
|
@@ -465,42 +447,37 @@ RDBで実現するためには、 @Items@ テーブル、
|
|
465
447
|
?> item.key,
|
466
448
|
?> item.title]
|
467
449
|
>> end
|
468
|
-
[2, "http://www.
|
469
|
-
[1, "
|
470
|
-
[1, "http://
|
450
|
+
[2, "http://www.ruby-doc.org/", "Ruby-Doc.org: Documenting the Ruby Language"]
|
451
|
+
[1, "https://rubygems.org/", "RubyGems.org | your community gem host"]
|
452
|
+
[1, "http://ranguba.org/", "Fulltext search by Ruby with groonga - Ranguba"]
|
471
453
|
=> nil
|
472
454
|
</pre>
|
473
455
|
|
474
|
-
@n_sub_records@
|
475
|
-
|
476
|
-
|
456
|
+
@n_sub_records@ is the number of records in each group.
|
457
|
+
It is similar value as count() function of a query including "GROUP
|
458
|
+
BY" in SQL.
|
477
459
|
|
478
|
-
h2.
|
460
|
+
h2. more complex search
|
479
461
|
|
480
|
-
|
462
|
+
Now, you challenge the more useful search.
|
481
463
|
|
482
|
-
|
483
|
-
出する必要性に迫られます。
|
464
|
+
You should calcurate goodness of fit of search explicitly.
|
484
465
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
保するためにはユーザのコメントも是非対象に含めたいところです。
|
466
|
+
You can use @Items.title@ and @Comments.content@ as search targets now.
|
467
|
+
@Items.title@ is the a few reliable information taken from each
|
468
|
+
original pages. On the other hands, @Comments.content@ is the less
|
469
|
+
reliable information because this depends on users of bookmark
|
470
|
+
application.
|
491
471
|
|
492
|
-
|
472
|
+
Then, you search records with this policy:
|
493
473
|
|
494
|
-
*
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
が複数存在した場合は、それぞれの @comment@ のスコアの
|
500
|
-
和を、該当するitemのスコアとする。
|
474
|
+
* Search item matched @Items.title@ or @Comments.content@.
|
475
|
+
* Add 10 times heavier weight to socres of each record matched
|
476
|
+
@Items.title@ than ones of @Comments.comment@.
|
477
|
+
* If multi @comment@ of one item are matched keyword, specify the sum
|
478
|
+
of scores of each @coments@ as score of the item.
|
501
479
|
|
502
|
-
|
503
|
-
めます。
|
480
|
+
On this policy, you try to type below:
|
504
481
|
|
505
482
|
<pre>
|
506
483
|
!!!irb
|
@@ -515,8 +492,8 @@ h2. 少し複雑な検索
|
|
515
492
|
#<Groonga::Hash ..., size: <4>>
|
516
493
|
</pre>
|
517
494
|
|
518
|
-
_ruby_comments_
|
519
|
-
|
495
|
+
You group the results of _ruby_comments_ in each item and union
|
496
|
+
_ruby_items_ .
|
520
497
|
|
521
498
|
<pre>
|
522
499
|
!!!irb
|
@@ -525,11 +502,11 @@ unionして出力します。
|
|
525
502
|
>> ruby_items.sort([{:key => "_score", :order => "descending"}]).each do |record|
|
526
503
|
>> p [record.score, record.title]
|
527
504
|
>> end
|
528
|
-
[
|
505
|
+
[22, "Ruby-Doc.org: Documenting the Ruby Language"]
|
506
|
+
[11, "Fulltext search by Ruby with groonga - Ranguba"]
|
507
|
+
[10, "Ruby Programming Language"]
|
529
508
|
[10, "Ruby"]
|
530
|
-
[
|
531
|
-
[10, "オブジェクトスクリプト言語Ruby"]
|
532
|
-
[2, "Matzにっき"]
|
509
|
+
[1, "RubyGems.org | your community gem host"]
|
533
510
|
</pre>
|
534
511
|
|
535
|
-
|
512
|
+
Then, you get the result.
|