Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
南宫伊儿
elasticsearch-analysis-ik
提交
beb47553
E
elasticsearch-analysis-ik
项目概览
南宫伊儿
/
elasticsearch-analysis-ik
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
elasticsearch-analysis-ik
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
beb47553
编写于
3月 05, 2015
作者:
weixin_43283383
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #56 from rockybean/master
optimize Dictionary reload process
上级
d60e7a68
d99555da
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
13 deletion
+41
-13
README.textile
README.textile
+19
-0
src/main/java/org/wltea/analyzer/dic/Dictionary.java
src/main/java/org/wltea/analyzer/dic/Dictionary.java
+13
-8
src/main/java/org/wltea/analyzer/dic/Monitor.java
src/main/java/org/wltea/analyzer/dic/Monitor.java
+9
-5
未找到文件。
README.textile
浏览文件 @
beb47553
...
@@ -223,6 +223,25 @@ here is the query result
...
@@ -223,6 +223,25 @@ here is the query result
have fun.
have fun.
热更新IK分词使用方法
----------
目前该插件支持热更新IK分词,通过上文在ik配置文件中提到的如下配置
<pre>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">location</entry>
<!--用户可以在这里配置远程扩展停止词字典-->
<entry key="remote_ext_stopwords">location</entry>
</pre>
其中`location`是指一个url,比如`http://yoursite.com/getCustomDict`,该请求只需满足一下两点即可完成分词热更新。
1. 该http请求需要返回两个头部,一个是`Last-Modified`,一个是`ETags`,这两者都是字符串类型,只要有一个发生变化,该插件就会去抓取新的分词进而更新词库。
2. 该http请求返回的内容格式是一行一个分词,换行符用`\n`即可。
满足上面两点要求就可以实现热更新分词了,不需要重启es实例。
常见问题:
常见问题:
-------------
-------------
...
...
src/main/java/org/wltea/analyzer/dic/Dictionary.java
浏览文件 @
beb47553
...
@@ -77,7 +77,7 @@ public class Dictionary {
...
@@ -77,7 +77,7 @@ public class Dictionary {
* 配置对象
* 配置对象
*/
*/
private
Configuration
configuration
;
private
Configuration
configuration
;
p
rivate
ESLogger
logger
=
null
;
p
ublic
static
ESLogger
logger
=
Loggers
.
getLogger
(
"ik-analyzer"
)
;
private
static
ScheduledExecutorService
pool
=
Executors
.
newScheduledThreadPool
(
1
);
private
static
ScheduledExecutorService
pool
=
Executors
.
newScheduledThreadPool
(
1
);
...
@@ -89,8 +89,7 @@ public class Dictionary {
...
@@ -89,8 +89,7 @@ public class Dictionary {
public
static
final
String
PATH_DIC_STOP
=
"ik/stopword.dic"
;
public
static
final
String
PATH_DIC_STOP
=
"ik/stopword.dic"
;
private
Dictionary
(){
private
Dictionary
(){
logger
=
Loggers
.
getLogger
(
"ik-analyzer"
);
}
}
/**
/**
...
@@ -367,11 +366,11 @@ public class Dictionary {
...
@@ -367,11 +366,11 @@ public class Dictionary {
}
}
response
.
close
();
response
.
close
();
}
catch
(
ClientProtocolException
e
)
{
}
catch
(
ClientProtocolException
e
)
{
e
.
printStackTrace
(
);
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
e
.
printStackTrace
(
);
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
}
return
buffer
;
return
buffer
;
}
}
...
@@ -638,8 +637,14 @@ public class Dictionary {
...
@@ -638,8 +637,14 @@ public class Dictionary {
public
void
reLoadMainDict
(){
public
void
reLoadMainDict
(){
logger
.
info
(
"重新加载词典..."
);
logger
.
info
(
"重新加载词典..."
);
loadMainDict
();
// 新开一个实例加载词典,减少加载过程对当前词典使用的影响
loadStopWordDict
();
Dictionary
tmpDict
=
new
Dictionary
();
tmpDict
.
configuration
=
getSingleton
().
configuration
;
tmpDict
.
loadMainDict
();
tmpDict
.
loadStopWordDict
();
_MainDict
=
tmpDict
.
_MainDict
;
_StopWords
=
tmpDict
.
_StopWords
;
logger
.
info
(
"重新加载词典完毕..."
);
}
}
}
}
src/main/java/org/wltea/analyzer/dic/Monitor.java
浏览文件 @
beb47553
...
@@ -9,7 +9,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
...
@@ -9,7 +9,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.client.HttpClients
;
public
class
Monitor
implements
Runnable
{
public
class
Monitor
implements
Runnable
{
private
static
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
private
static
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
/*
/*
* 上次更改时间
* 上次更改时间
...
@@ -40,7 +40,7 @@ public class Monitor implements Runnable {
...
@@ -40,7 +40,7 @@ public class Monitor implements Runnable {
*/
*/
public
void
run
()
{
public
void
run
()
{
//超时设置
//超时设置
RequestConfig
rc
=
RequestConfig
.
custom
().
setConnectionRequestTimeout
(
10
*
1000
)
RequestConfig
rc
=
RequestConfig
.
custom
().
setConnectionRequestTimeout
(
10
*
1000
)
.
setConnectTimeout
(
10
*
1000
).
setSocketTimeout
(
15
*
1000
).
build
();
.
setConnectTimeout
(
10
*
1000
).
setSocketTimeout
(
15
*
1000
).
build
();
...
@@ -72,13 +72,17 @@ public class Monitor implements Runnable {
...
@@ -72,13 +72,17 @@ public class Monitor implements Runnable {
last_modified
=
response
.
getLastHeader
(
"Last-Modified"
)==
null
?
null
:
response
.
getLastHeader
(
"Last-Modified"
).
getValue
();
last_modified
=
response
.
getLastHeader
(
"Last-Modified"
)==
null
?
null
:
response
.
getLastHeader
(
"Last-Modified"
).
getValue
();
eTags
=
response
.
getLastHeader
(
"ETags"
)==
null
?
null
:
response
.
getLastHeader
(
"ETags"
).
getValue
();
eTags
=
response
.
getLastHeader
(
"ETags"
)==
null
?
null
:
response
.
getLastHeader
(
"ETags"
).
getValue
();
}
}
}
else
{
Dictionary
.
logger
.
info
(
"remote_ext_dict {} return bad code {}"
,
location
,
response
.
getStatusLine
().
getStatusCode
()
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
Dictionary
.
logger
.
error
(
"remote_ext_dict {} error!"
,
e
,
location
);
}
finally
{
}
finally
{
try
{
try
{
response
.
close
();
if
(
response
!=
null
)
{
response
.
close
();
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录