今天接到客户新的需求,要求在分词上接近,现实更人性化,于是我将原先来分词器IK_CAnalyzer 换成最新的 PaodingAnalyzer, 不过.....这其中的曲折太多了...
首先,我下载了最新的paoding包 paoding-analysis-2.0.4-alpha2,将jar包导入classpath,将词典导入到classpath我设置好paoding.dic.home
并将compass的sping配置做了修改,如下
修改前:
<prop key="compass.engine.analyzer.default.type">org.mira.lucene.analysis.IK_CAnalyzer</prop>
修改后:
<prop key="compass.engine.analyzer.default.type">net.paoding.analysis.analyzer.PaodingAnalyzer</prop>
启动,报错如下
java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1412)
at com.caucho.loader.DynamicClassLoader.findClassImpl(DynamicClassLoader.java:1282)
at com.caucho.loader.DynamicClassLoader.loadClassImpl(DynamicClassLoader.java:1184)
at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1128)
at com.caucho.loader.DynamicClassLoader.loadClass(DynamicClassLoader.java:1113)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at net.paoding.analysis.analyzer.impl.MostWordsTokenCollector.collect(MostWordsTokenCollector.java:41)
at net.paoding.analysis.analyzer.PaodingTokenizer.collect(PaodingTokenizer.java:146)
at net.paoding.analysis.knife.CombinatoricsKnife.doCollect(CombinatoricsKnife.java:258)
at net.paoding.analysis.knife.CombinatoricsKnife.collectIfNotNoise(CombinatoricsKnife.java:227)
意思是说我继承了一个final类,这个final类是哪个类呢,是 lucene-core.jar下面的org.apache.lucene.org.apache.lucene.analysis.Token类,这个类被声明为final,但paoding分词会继承这个类,怎么办呢,我查看了下载的paoding-analysis-2.0.4-alpha2包,里面的lucene jar包是2.2版本的,于是我将我工程的lucene版本升至2.2.
启动,又报错,如下
java.lang.NoSuchMethodError: org/apache/lucene/document/Document.add(Lorg/apache/lucene/document/Field;)V
找不到方法,Lucene从2.0版本后Document增加Field时采用的是new Field(...)方法,而我的compass.jar是1.0版本的,于是我又去下了个最新的compass.jar 2.02版本的.
启动,又报错
找不到 org.compass.spring.device.hibernate.SpringHibernate3GpsDevice
看了一下jar包里的类,这个类改成org.compass.spring.device.hibernate.dep.SpringHibernate3GpsDevice了...
再次启动后终于正常了...