﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; Lucene</title>
	<atom:link href="http://laigw.name/tag/lucene/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>发布自己写的Lucene中文分析器&#8211;NGramAnalyzer</title>
		<link>http://laigw.name/post/91.html</link>
		<comments>http://laigw.name/post/91.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 08:15:36 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[搜索引擎/SEO]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[nGram]]></category>
		<category><![CDATA[中文分析]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=91</guid>
		<description><![CDATA[毕业设计期间，因需要自己写了一个基于Lucene的中文分析器NGramAnalyzer，它包括三个类，分别是：
NGramAnalyzer
NGramFilter
NGramTokenizer
该分析器基于ChineseAnalyzer而实现，但不同于ChineseAnalyzer和车东写的CJKAnalyzer， NGramAnalyzer不仅仅支持“切字”和“切二字词”，它可以支持任意长度词的切分。这点特性使得NGramAnalyzer特别适合做 NGram的中文分析。事实上，它也是我为了做NGram的中文分析而特意写的（因此，也把它的名字取为“NGram*”的形式）。这里特拿出来跟大家分享！希望对有兴趣的朋友有点点帮助，也希望大家能多给我意见，让我可以做更多的改进，^_^
这里，把这NGramAnalyzer的三个类贴出来。在每个类的编写过程中，我都做了很详细的注释，读者应该比较容易看明白。
下面是第一个类，也是最主要的一个类：NGramTokenizer。


&#160;查看代码 JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
//: cn.org.gavin.analysis: NGramTokenizer.java
&#160;
package cn.org.gavin.analysis;
&#160;
import java.io.Reader;
&#160;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.Tokenizer;
&#160;
public final class NGramTokenizer extends Tokenizer &#123;
&#160;
// ~~ 类变量(静态变量)
&#160;
/* buffer缓冲区大小 */
private final static int MAX_WORD_LEN = 127;
&#160;
/*
* ioBuffer缓冲区大小
*
* !注意：该常量大小与n有关，理论上，IO_BUFFER_SIZE应满足 (IO_BUFFER_SIZE + 1) -
* (n-1) &#62;= 0; 即：IO_BUFFER_SIZE &#62;= n-2。 之所以有这个规定，是为了防止“二次修正”的出现。
* 例如：
* 设 String s = &#34;深圳大学是深圳的大学&#34;; IO_BUFFER_SIZE = 4, n = 7 则
* 读取过程：
* ioBuffer ioBufferEx
* [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/91.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>全文检索引擎工具包Lucene源码分析－－analysis包</title>
		<link>http://laigw.name/post/88.html</link>
		<comments>http://laigw.name/post/88.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 08:07:54 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[搜索引擎/SEO]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[源码分析]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=88</guid>
		<description><![CDATA[我的毕业设计是基于全文检索引擎工具包Luncene的analysis包而实现的，期间查看了该包的源码并作了一些分析，现在贴出来以供参考。
注：这里分析的只是analysis包的一些基本类，而不是全部。
1、Token类：


&#160;查看代码 JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.apache.lucene.analysis;
&#160;
public final class Token&#123;
&#160;
String termText; // 词项文本（the text of the term）
int startOffset; // Token在源文本中的起始位置（start in source text）
int endOffset; // Token在源文本中的结束位置（end in source text）
String type = &#34;word&#34;; //~ Token的词类型，默认是&#34;word&#34;（lexical type, default is &#34;word&#34;）
//: 附：lexical type:
//: single =&#62; ASCII
//: double =&#62; non-ASCII
//: word =&#62; default
&#160;
private int positionIncrement = 1; // 位移增量，即TokenStream里当前Token与
// 先前某一个Token之间的位移差，默认为1
&#160;
//~ 第一个构造器
public Token&#40;String text, [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/88.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

