我在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
答案 0 :(得分:4)
如果查看Javadoc for TokenFilterFactory,构造函数将获取Map<String,String>
参数。尝试将ContentFilterFactory
构造函数更新为:
public ContentFilterFactory(Map<String, String> args) {
super(args);
}