要解决此问题,我将我的自定义jar移到了自定义文件夹$ {solr_instance}/contrib/hybris/lib,没有任何其他Lucene库.而且,我的solrconfig.xml已经有一个链接:<lib dir="${solr.install.dir:../../../..}/contrib/hybris/lib" regex=".*\.jar" />因此,可以得出结论,这种异常是指类路径歧义性问题,这使Solr感到困惑. I'm using 4.10.3 solr and after I implemented Factory with Filterimport org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.util.TokenFilterFactory;import java.util.Map;public class CustomFilterFactory extends TokenFilterFactory {protected CustomFilterFactory(Map<String, String> args) { super(args);}@Overridepublic TokenStream create(TokenStream tokenStream) { return new CustomFilter(tokenStream);}}and when Solr starts, I'm getting strange errors in log:Caused by:java.lang.ClassCastException: class org.apache.lucene.analysis.tr.ApostropheFilterFactoryat java.lang.Class.asSubclass(Class.java:3116)at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:141)at org.apache.lucene.analysis.util.AnalysisSPILoader.reload(AnalysisSPILoader.java:79)at org.apache.lucene.analysis.util.AnalysisSPILoader.<init>(AnalysisSPILoader.java:60)at org.apache.lucene.analysis.util.AnalysisSPILoader.<init>(AnalysisSPILoader.java:49)at org.apache.lucene.analysis.util.TokenFilterFactory.<clinit>(TokenFilterFactory.java:31)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:270)at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:474)at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:593)at org.apache.solr.schema.FieldTypePluginLoader$1.create(FieldTypePluginLoader.java:306)at org.apache.solr.schema.FieldTypePluginLoader$1.create(FieldTypePluginLoader.java:299)at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:325)at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:486)Any idea what could cause this state?Field definition:<field name="ii" type="customFilter" indexed="true" stored="false" required="false" multiValued="false"/><fieldType name="customFilter" class="solr.TextField"> <analyzer> <charFilter class="com.nosql.search.solr.CustomFilterFactory" /> </analyzer></fieldType>I'm using same Java version for my custom jar with filter and for starting Solr.It works if I remove the reference to CustomFilterFactory. 解决方案 I had the same issue with Solr 6.4. But my solr is deployed within the Hybris 6 framework. The point is that I tried to add my custom token filter library directly to solr server libraries ${solr_instance}/server/lib, then I got an exception that the engine could find the parent lucene class TokenFilterFactory. After the adding of the related jars lucene-analysers-common-x, lucene-core-x, I got the same error as yours (java.lang.ClassCastException: class org.apache.lucene.analysis.tr.ApostropheFilterFactory)To resolve this I just moved my custom jar to the custom folder ${solr_instance}/contrib/hybris/lib without any additional lucene libs. Moreover my solrconfig.xml already had a link to it: <lib dir="${solr.install.dir:../../../..}/contrib/hybris/lib" regex=".*\.jar" />So, one can conclude that this kind of exception refers to classpath ambiguity issue, which confuses Solr. 这篇关于尝试在solr中应用自定义过滤器时发生ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-30 07:48