gpt4 book ai didi

java - Solr ClassCastException 与自定义 TokenFilterFactory

转载 作者:行者123 更新时间:2023-12-02 09:53:16 24 4
gpt4 key购买 nike

我在使用 Solr 6.3.0 创建核心时遇到问题我有扩展 lucene 的 TokenFilterFactory 的类

public class CustomTokenFactory extends TokenFilterFactory 

在solr核心solrconfig.xml中

<lib dir="${solr.install.dir:../../../..}/target/" regex="myjar-1.0.0.jar" />

当我尝试启动 solr 时 - 发生 ClassCastException

Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "MyAnalyser": Plugin init failure for [schema.xml] analyzer/tokenizer: class com.myjar.CustomTokenFactory 
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:182)
at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:491)
... 14 more
Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] analyzer/tokenizer: class com.myjar.CustomTokenFactory
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:182)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:361)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:104)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:53)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:152)
... 15 more
Caused by: java.lang.ClassCastException: class com.myjar.CustomTokenFactory
at java.lang.Class.asSubclass(Class.java:3404)
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:540)
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:625)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:341)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:334)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:152)
... 19 more

我的 pom 包含以下 solr\lucene 库

    <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.jwordnet/jwnl -->
<dependency>
<groupId>net.sf.jwordnet</groupId>
<artifactId>jwnl</artifactId>
<version>1.4_rc3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-tools -->
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<!-- for wikipedia cleanup -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-maxent -->
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-maxent</artifactId>
<version>3.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-uima -->
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-uima</artifactId>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.solr/solr-analysis-extras -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-analysis-extras</artifactId>
<version>6.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.1</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-benchmark -->
<!-- for indexing wikipedia -->
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-benchmark -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-benchmark</artifactId>
<version>6.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>6.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

solr 中出现此类错误的原因是什么?我的第一个想法是 lib 版本不匹配 - 但到处都是 *-6.3.0.jar

依赖树是这样的:

 +- junit:junit:jar:3.8.1:test
[INFO] +- net.sf.jwordnet:jwnl:jar:1.4_rc3:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] +- org.apache.opennlp:opennlp-tools:jar:1.5.3:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.21:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] +- org.apache.opennlp:opennlp-maxent:jar:3.0.3:compile
[INFO] +- org.apache.opennlp:opennlp-uima:jar:1.6.0:compile
[INFO] +- org.apache.solr:solr-analysis-extras:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-common:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-icu:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-kuromoji:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-morfologik:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-phonetic:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-smartcn:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-analyzers-stempel:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-backward-codecs:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-classification:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-codecs:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-core:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-expressions:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-grouping:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-highlighter:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-join:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-memory:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-misc:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-queries:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-queryparser:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-sandbox:jar:6.3.0:provided
[INFO] | +- org.apache.lucene:lucene-spatial-extras:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-suggest:jar:6.3.0:provided
[INFO] | +- com.carrotsearch:hppc:jar:0.7.1:provided
[INFO] | +- com.facebook.presto:presto-parser:jar:0.122:provided
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.5.4:provided
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.5.4:provided
[INFO] | +- com.github.ben-manes.caffeine:caffeine:jar:1.0.1:provided
[INFO] | +- com.google.guava:guava:jar:14.0.1:compile
[INFO] | +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] | +- com.ibm.icu:icu4j:jar:56.1:compile
[INFO] | +- com.tdunning:t-digest:jar:3.1:provided
[INFO] | +- commons-cli:commons-cli:jar:1.2:compile
[INFO] | +- commons-codec:commons-codec:jar:1.10:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.2:provided
[INFO] | +- commons-configuration:commons-configuration:jar:1.6:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- commons-io:commons-io:jar:2.5:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:provided
[INFO] | +- io.airlift:slice:jar:0.10:provided
[INFO] | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] | +- joda-time:joda-time:jar:2.2:compile
[INFO] | +- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.antlr:antlr4-runtime:jar:4.5.1-1:provided
[INFO] | +- org.apache.commons:commons-exec:jar:1.3:provided
[INFO] | +- org.apache.curator:curator-client:jar:2.8.0:provided
[INFO] | +- org.apache.curator:curator-framework:jar:2.8.0:provided
[INFO] | +- org.apache.curator:curator-recipes:jar:2.8.0:provided
[INFO] | +- org.apache.hadoop:hadoop-annotations:jar:2.7.2:provided
[INFO] | | \- jdk.tools:jdk.tools:jar:1.8:system
[INFO] | +- org.apache.hadoop:hadoop-auth:jar:2.7.2:provided
[INFO] | +- org.apache.hadoop:hadoop-common:jar:2.7.2:provided
[INFO] | +- org.apache.htrace:htrace-core:jar:3.2.0-incubating:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.4.1:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.4.1:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] | +- org.carrot2:morfologik-fsa:jar:2.1.1:provided
[INFO] | +- org.carrot2:morfologik-polish:jar:2.1.1:provided
[INFO] | +- org.carrot2:morfologik-stemming:jar:2.1.1:provided
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | +- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] | +- org.eclipse.jetty:jetty-continuation:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-deploy:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-http:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-io:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-jmx:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-rewrite:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-security:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-server:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-servlet:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-servlets:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-util:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-webapp:jar:9.3.8.v20160314:provided
[INFO] | +- org.eclipse.jetty:jetty-xml:jar:9.3.8.v20160314:provided
[INFO] | +- org.locationtech.spatial4j:spatial4j:jar:0.6:compile
[INFO] | +- org.noggit:noggit:jar:0.6:compile
[INFO] | +- org.ow2.asm:asm:jar:5.1:provided
[INFO] | +- org.ow2.asm:asm-commons:jar:5.1:provided
[INFO] | +- org.restlet.jee:org.restlet:jar:2.3.0:provided
[INFO] | +- org.restlet.jee:org.restlet.ext.servlet:jar:2.3.0:provided
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.7:compile
[INFO] +- org.apache.solr:solr-solrj:jar:6.3.0:compile
[INFO] +- org.apache.hadoop:hadoop-hdfs:jar:2.7.1:compile
[INFO] | +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] | +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] | +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] | +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO] | | \- asm:asm:jar:3.1:compile
[INFO] | +- commons-daemon:commons-daemon:jar:1.0.13:compile
[INFO] | +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] | +- xmlenc:xmlenc:jar:0.52:compile
[INFO] | +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO] | +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.3.04:compile
[INFO] | \- org.fusesource.leveldbjni:leveldbjni-all:jar:1.8:compile
[INFO] +- org.apache.lucene:lucene-benchmark:jar:6.3.0:compile
[INFO] | +- org.apache.lucene:lucene-facet:jar:6.3.0:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.17:compile
[INFO] | \- org.apache.commons:commons-compress:jar:1.11:compile
[INFO] +- org.apache.solr:solr-core:jar:6.3.0:provided
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:3.9.2:compile
[INFO] +- com.apple:AppleJavaExtensions:jar:1.4:compile
[INFO] +- de.jollyday:jollyday:jar:0.4.9:compile
[INFO] +- com.io7m.xom:xom:jar:1.2.10:compile
[INFO] | \- xalan:xalan:jar:2.7.0:compile
[INFO] +- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO] +- org.glassfish:javax.json:jar:1.0.4:compile
[INFO] +- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.4.0-b180830.0359:compile
[INFO] +- com.sun.xml.bind:jaxb-core:jar:2.3.0.1:compile
[INFO] \- com.sun.xml.bind:jaxb-impl:jar:2.4.0-b180830.0438:compile

有什么建议吗?谢谢!

最佳答案

我发现了问题。它与类加载无关,而是与schema.xml相关。 。我在 <tokenizer> 中定义了我的 CustomTokenFactory标签而不是 <filter>标签。 solr 正在尝试做 asSubclassTokenizerFactory 。远程调试在这种情况下很有帮助。

关于java - Solr ClassCastException 与自定义 TokenFilterFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56163831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com