java(jsp)搜索分词IKAnalyzer+Lucene分词

csi lv深圳网站建设:www.sz886 java(jsp)搜索分词IKAnalyzer+Lucene分词
起源:由于现在搜索引擎可以根据搜索词自动拆分出不同的词来搜索信息,更好得到用户
想要搜索的信息如(深圳网站建设网络技术,会被拆分为深圳网站建设与网络技术铠甲式防护罩
两个不同的词),所以我们制作网站的时候搜索信息有时候也是需要使用到分词的。
java IKAnalyzer分词jar包
IKAnalyzer.jar和lucene-core.jar
需要引入l到项目的src目录中,下面是代码
<?xml version="1.0"encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM"java.sun/dtd/properties.dtd">
<properties>
<comment>IK Analyzer扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典-->
<entry key="ext_dict">ext.dic;</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">stopword.dic;</entry>
</properties>
需要引入stopword.dic到项目src目录中,下面是代码
a
an
and
are
as
at
be
but
by
for
if
in
into
is
it
no
not
of
on
短程蒸馏器or
such
that
the
their
then
there
these
they
this
to
was
will
with
需要引入ext.dic到项目的src目录中,下面是代码
深圳网站建设安瓿印字机
网络技术夜来香精油
正弦波发生器
上面的两个词是我们自己自定义,大家可以自定义输入,记得ext.dic的文字编辑要跟项目是一样如(utf-8),可以直接使用dw修改编辑
最后是java代码
public class IKAnalyzerTest{
public static void main(String[]args)throws IOException {
String keyWord="深圳网站建设公司独占网络技术制作分词效果";
queryWords(keyWord);
}
public static void queryWords(String query)throws IOException{
Configuration Instance();
//System.out.MainDictionary());//
//System.out.QuantifierDicionary());
List<String>list=new ArrayList<String>();
StringReader input=new
im());
IKSegmenter ikSeg=new IKSegmenter(input,true);
for(Lexeme ();lexeme!=null; ()){
System.out.LexemeText()+"-");
}
}
}
效果好下

本文发布于:2024-09-23 14:36:02,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/277859.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:网站   建设   网络
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议