elasticsearch 刷新词典

阅读更多

elasticsearch开启加载外部词典功功能后,会每60s间隔进行刷新字典。

 

public void loadDic(HttpServletRequest req,HttpServletResponse response){

 

String eTag =req.getParameter("If-None-Match");

try {

OutputStream out= response.getOutputStream();

List list=new ArrayList();

list.add("我中国");

list.add("我爱你爱我");

String oldEtag = list.size() + "";

StringBuffer sb=new StringBuffer();

if (oldEtag != eTag) {

for (String str : list) {

if(StringUtils.isNotBlank(str)){

sb.append("\r\n");

}

sb.append(str+"\r\n");

}

}

String data=sb.toString();

 

response.setHeader("Last-Modified", String.valueOf(list.size()));

response.setHeader("ETag",String.valueOf(list.size()));

response.setContentType("text/plain; charset=gbk");

out.write(data.getBytes());

out.flush();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

你可能感兴趣的:(elasticsearch 刷新词典)