我在 Solr 中实现了一个示例自定义过滤器,并将 fieldtype:contentType 配置为在索引分析阶段使用过滤器,如下所示;
<fieldType name="contentType" class="solr.TextField">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="com.solr.test.analyzer.ContentFilterFactory"/>
</analyzer>
</fieldType>
下面是我的自定义过滤器工厂类:
public class ContentFilterFactory extends TokenFilterFactory {
public ContentFilterFactory() {
super();
}
@Override
public TokenStream create(TokenStream input) {
return new ContentFilter(input);
}
}
启动 Solr 4.5.0 服务器时,加载 ContentFilterFactory 实例时出现以下错误。根本原因是 java.lang.NoSuchMethodException:com.solr.test.analyzer.ContentFilterFactory.(java.util.Map)
我需要在 FilterFactory 中包含一个 init() 方法吗?如果是这样,我应该在其中包含什么?有人可以帮我解决这个错误。
Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] analyzer/filter: Error instantiating class: 'com.solr.test.analyzer.ContentFilterFactory'
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
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)
... 14 more
Caused by: org.apache.solr.common.SolrException: Error instantiating class: 'com.solr.test.analyzer.ContentFilterFactory'
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
at org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
at org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
... 18 more
Caused by: java.lang.NoSuchMethodException: com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getConstructor(Class.java:1718)
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
... 21 more